Skip to main content

Tenancy primitives for Flametrench: organizations, memberships, and atomic invitation acceptance with the mem_/tup_ duality.

Project description

flametrench-tenancy

CI

Python SDK for the Flametrench tenancy specification: organizations, memberships (with the mem_/tup_ duality), and atomic invitation acceptance.

Status: v0.2.0 (stable). Includes the production-ready PostgresTenancyStore alongside the in-memory reference store. Per ADR 0013 the Postgres adapter cooperates with adopter-side outer transactions via savepoints when nested (psycopg3 connection.transaction() handles this automatically).

The same behavioral guarantees that gate @flametrench/tenancy (Node), flametrench/tenancy (PHP), and dev.flametrench:tenancy (Java) hold here:

  • Revoke-and-re-add on role changes, with a replaces chain for audit history.
  • Sole-owner protection on every path that could leave an org without an active owner (change_role, suspend_membership, self_leave).
  • Atomic invitation acceptance — user creation, membership insertion, owner-role tuple, AND pre-tuple expansion all in one transition.
  • Role hierarchy on admin_remove — admins cannot remove peers or higher-ranked members.
  • mem_/tup_ duality — every active membership is shadowed by a corresponding (usr, role, org) tuple, kept in lockstep with mem.status.
from datetime import datetime, timedelta, timezone

from flametrench_ids import generate
from flametrench_tenancy import InMemoryTenancyStore, PreTuple, Role

store = InMemoryTenancyStore()
alice = generate("usr")
result = store.create_org(alice)
print(result.org.id, result.owner_membership.role)  # → org_..., Role.OWNER

# Invite a new user and pre-attach an editor grant on a project.
project_id = generate("org")[4:]
inv = store.create_invitation(
    org_id=result.org.id,
    identifier="newbie@example.com",
    role=Role.MEMBER,
    invited_by=alice,
    expires_at=datetime.now(timezone.utc) + timedelta(days=7),
    pre_tuples=[PreTuple(relation="editor", object_type="proj", object_id=project_id)],
)

out = store.accept_invitation(inv.id)
print(out.membership.role, out.materialized_tuples)

Installation

pip install flametrench-tenancy

Requires Python 3.11+. Depends on flametrench-ids for usr_/org_/mem_/inv_ id generation.

License

Apache-2.0. See LICENSE and NOTICE.

Copyright 2026 NDC Digital, LLC.

Project details


Download files

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

Source Distribution

flametrench_tenancy-0.3.0.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

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

flametrench_tenancy-0.3.0-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file flametrench_tenancy-0.3.0.tar.gz.

File metadata

  • Download URL: flametrench_tenancy-0.3.0.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flametrench_tenancy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8786f9cd82e153e27672ee1ba056270d3bd83301adcf3ed96c6400eba692c9d9
MD5 4734a2c92fd58de1cb3d4ac47fe6f12d
BLAKE2b-256 2bc72f6e70a626e58a83f3aae617b124c5bc90eeaffb05aca08a5cb1aa4e1e2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for flametrench_tenancy-0.3.0.tar.gz:

Publisher: publish.yml on flametrench/tenancy-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flametrench_tenancy-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flametrench_tenancy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15fb3ad678d7c46fd90d1d2daa6354f4fc7eaf4e5cbfdd480dc17d3bbf8f1d42
MD5 6827178e8086b2715db38e5bacf253d9
BLAKE2b-256 60c2ff75e6d242028bbe52984cf66417eb6b1cbe02ede33b24fed66bb290598f

See more details on using hashes here.

Provenance

The following attestation bundles were made for flametrench_tenancy-0.3.0-py3-none-any.whl:

Publisher: publish.yml on flametrench/tenancy-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page