Skip to main content

lexigram-contracts

Core types and protocols for the Lexigram Framework.


Overview

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.

Full documentation: docs.lexigram.dev

Install

uv add lexigram-contracts

Quick Start

Result type

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")

Domain models

from lexigram.domain.models import Entity, ValueObject
from lexigram.domain import AggregateRoot
from lexigram.contracts.domain.events import DomainEvent


class UserCreated(DomainEvent):
    user_id: str
    email: str


class User(AggregateRoot):
    email: str

Protocols

from lexigram.contracts.infra.cache import CacheBackendProtocol
from lexigram.contracts.data import DatabaseProviderProtocol
from lexigram.contracts.security.secrets import SecretStoreProtocol

Key Modules

Module What it contains
lexigram.result Result[T, E], Ok, Err, as_result(), as_result_sync(), try_catch(), ResultPipeline
lexigram.domain.models DomainModel, Entity, ValueObject (concrete domain models, in core lexigram)
lexigram.domain AggregateRoot (re-exported from lexigram.domain.models.aggregate)
lexigram.contracts.domain.base DomainModelProtocol, ID
lexigram.contracts.domain.events DomainEvent
lexigram.contracts.infra.cache CacheBackendProtocol
lexigram.contracts.data DatabaseProviderProtocol
lexigram.contracts.security.secrets SecretStoreProtocol
lexigram.contracts.core.di ContainerRegistrarProtocol, ContainerResolverProtocol
lexigram.contracts.core.provider ProviderProtocol, ProviderPriority
lexigram.contracts.core.registry RegistryProtocol, StrategyRegistryProtocol, BackendRegistryProtocol
lexigram.contracts.exceptions LexigramError, full error hierarchy

Key Source Files

File What it contains
src/lexigram/contracts/__init__.py Lazy-loading re-exports of all public types
src/lexigram/result/ Result type and Ok/Err helpers
src/lexigram/contracts/domain/ DomainModelProtocol, DomainEvent
src/lexigram/contracts/core/ Container, Provider, Registry protocols
src/lexigram/contracts/exceptions/ LexigramError and domain error hierarchies

Design Principles

  • 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lexigram_contracts-0.1.4.tar.gz (379.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lexigram_contracts-0.1.4-py3-none-any.whl (409.4 kB view details)

Uploaded Python 3

File details

Details for the file lexigram_contracts-0.1.4.tar.gz.

File metadata

  • Download URL: lexigram_contracts-0.1.4.tar.gz
  • Upload date:
  • Size: 379.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for lexigram_contracts-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6ea2ce4b683ec0e68c58770c44b7da563ac9be9601e8994a2c342a07461c31e9
MD5 58ee56d69b4789d99e2ecc993c0ae650
BLAKE2b-256 a1ce2085c1cfa807649148c9e3a53e7b5c2252d8012cecea6bcad0d6eae13b5d

See more details on using hashes here.

File details

Details for the file lexigram_contracts-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for lexigram_contracts-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a071dbba06c6025f8e4755a0aae076aaa8d49d101b3b2c5ff52501daa34ecbb9
MD5 a6c0888e8cda97b3a3a864173ee36d3e
BLAKE2b-256 51c9f6f6ea22a956eaa2127c49494e08e39adda8f6cdd84255690b871c28c932

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.5008

1 file

0.1.5007

2 files

0.1.5004

2 files

0.1.5001

2 files

0.1.3010

2 files

0.1.3007

1 file

0.1.3006

1 file

0.1.3005

1 file

This release

0.1.4 This release

2 files

0.1.2

1 file

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page