Skip to content
GitHub

Quickstart

Install the package:

Terminal window
uv add lexigram-tenancy
import asyncio
from lexigram.app import Application
from lexigram.tenancy import TenancyModule, TenancyConfig
async def main() -> None:
config = TenancyConfig()
app = Application(name="my-app")
app.add_module(TenancyModule.configure(config=config))
async with Application.boot(name="my-app", modules=[TenancyModule.configure(config=config)]) as app:
from lexigram.contracts.tenancy.protocols import TenantProviderProtocol
provider = await app.container.resolve(TenantProviderProtocol)
result = await provider.create_tenant(
CreateTenantCommand(slug="acme", name="ACME Corp")
)
if result.is_ok():
tenant = result.unwrap()
print(f"Created tenant: {tenant.tenant_id}")
asyncio.run(main())
  • TenancyModule.configure() registered the tenancy provider stack (resolution chain, validator, lifecycle service, isolation strategies)
  • The TenantProviderProtocol was resolved from the container — backed by InMemoryTenantProvider by default
  • A tenant was created with slug acme and name ACME Corp
  • Guide — mental model, resolution chain, isolation strategies
  • Architecture — provider composition, contracts, lifecycle
  • Configuration — resolver order, TTLs, integration toggles
  • How-Tos — custom resolvers, SQL backend, per-tenant config overrides