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.4.0.tar.gz (32.9 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.4.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flametrench_tenancy-0.4.0.tar.gz
  • Upload date:
  • Size: 32.9 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.4.0.tar.gz
Algorithm Hash digest
SHA256 b1a76d097abf500e293fe61e5028de7249fbdb6a3eba985c7ba9cca9f52cd9ff
MD5 92b2b9a50139ea4ef517909d9da68dab
BLAKE2b-256 e03ddb1532f073945a1c85932c200c1b576a1564ef10d9e7d16c222d5a71c7cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for flametrench_tenancy-0.4.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.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flametrench_tenancy-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab84862b20a35e08951fd4c47520fe35b829d31317d449ff01286b033033b6b0
MD5 bc71504b5df1b0d98d87d3eba46aa88a
BLAKE2b-256 cc18f244c66e51c3ec0ac9b435cd52580fdc1f677fa4d0df73592c9b5a0f6c13

See more details on using hashes here.

Provenance

The following attestation bundles were made for flametrench_tenancy-0.4.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