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.1.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.1-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flametrench_tenancy-0.4.1.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.1.tar.gz
Algorithm Hash digest
SHA256 c26c87c932dfbe9c811257f340c737523376ce4f3cb0aae894a6fd52a386e04f
MD5 64462e4613ba6b5693a30595fc561218
BLAKE2b-256 455c95e367c6533cc55ac42f8cef319c0b65a299dae2253962628e2362a109d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flametrench_tenancy-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 315d402e731fa31822f774c963d00cfa2c5c876bb9bda763293c35424331c12d
MD5 05713fe27c699831b261df8c84a40360
BLAKE2b-256 490189961298e2dd1bcdd2d3d6f68f47688ab15ae4aa99d13cde0b900a1da064

See more details on using hashes here.

Provenance

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