Skip to content
GitHubDiscord

Contracts (lexigram-contracts)

Core types and protocols for the Lexigram Framework.


lexigram-contracts defines all Protocols, base types, Result types, domain models, and exception hierarchies used across the Lexigram ecosystem. It has zero runtime dependencies so it can be imported into any package — including thin integrations — without pulling in the full framework.

This package is the single source of truth for every interface in Lexigram. All other packages depend on contracts; no implementation package defines its own protocol that another package depends on.

Terminal window
uv add lexigram-contracts
from lexigram.result import Result, Ok, Err
async def find_user(user_id: str) -> Result[User, UserNotFound]:
user = await db.get(user_id)
if not user:
return Err(UserNotFound(user_id))
return Ok(user)
# Safe consumption
result = await find_user("u-123")
name = result.match(ok=lambda u: u.name, err=lambda e: "unknown")
from lexigram.contracts.domain.base import Entity, ValueObject
from lexigram.contracts.domain.aggregates import AggregateRoot
from lexigram.contracts.domain.events import DomainEvent
class UserCreated(DomainEvent):
user_id: str
email: str
class User(AggregateRoot):
email: str
from lexigram.contracts.cache import CacheBackend
from lexigram.contracts.data import DatabaseProviderProtocol
from lexigram.contracts.security.secrets import SecretStoreProtocol
ModuleWhat it contains
lexigram.resultResult[T, E], Ok, Err, ok(), err()
lexigram.contracts.core.containerContainerRegistrarImpl, ContainerResolverImpl
lexigram.contracts.core.providerProvider, ProviderPriority
lexigram.contracts.core.registryRegistry for type-keyed dispatch
lexigram.contracts.domain.baseEntity, ValueObject
lexigram.contracts.domain.aggregatesAggregateRoot
lexigram.contracts.domain.eventsDomainEvent
lexigram.contracts.cacheCacheBackend protocol
lexigram.contracts.dataDatabaseProviderProtocol
lexigram.contracts.security.secretsSecretStoreProtocol
lexigram.contracts.exceptionsLexigramError, full error hierarchy
FileWhat it contains
src/lexigram/contracts/__init__.pyLazy-loading re-exports of all public types
src/lexigram/result/Result type and Ok/Err helpers
src/lexigram/contracts/domain/Entity, ValueObject, AggregateRoot, DomainEvent
src/lexigram/contracts/core/Container, Provider, Registry protocols
src/lexigram/contracts/exceptions/LexigramError and domain error hierarchies
  • Zero dependencies — no third-party runtime imports
  • Protocol-only — defines interfaces, never implementations
  • Stable contract — all other Lexigram packages depend on this one; breaking changes are versioned