Skip to main content

Building blocks for zanzibar style ReBAC

Project description

zanzipy

Pythonic, minimal implementation of Zanzibar-style authorization (ReBAC) for real-world SaaS apps — not Google scale, but practical and solid. Bring your own persistence; everything else to model, write, and check permissions is here.

Why zanzipy? ✨

  • No extra services: embed in your app. Implement a tiny repo interface to use any storage (SQL/NoSQL/in-memory).
  • Zanzibar concepts: relations, permissions, unions/intersections/exclusions, tuple-to-userset (cross-namespace following).
  • Schema-first: validate rewrites and subject types at registration time.
  • Batteries-included engine: correctness-first checks and object listing with rule evaluation.

Project status 🚧

  • Early and evolving. Core primitives are implemented and tested, but the API may change.
  • Good fit if you want to bootstrap an ACL/Authorization/ReBAC system in Python without running a separate auth service.

Install

pip install zanzipy

Quick start (tiny example)

from zanzipy.client import ZanzibarClient
from zanzipy.models import Relation
from zanzipy.schema import (
    NamespaceDef,
    RelationDef,
    PermissionDef,
    SubjectReference,
    ComputedUsersetRule,
    UnionRule,
    SchemaRegistry,
)
from zanzipy.storage.repos import InMemoryRelationRepository

# Define a minimal schema: users and documents
user_ns = NamespaceDef(name="user")
doc_ns = NamespaceDef(
    name="document",
    relations=(
        RelationDef(
            name="owner",
            allowed_subjects=SubjectReference(namespace="user"),
        ),
        RelationDef(
            name="viewer",
            allowed_subjects=SubjectReference(namespace="user"),
        ),
    ),
    permissions=(
        PermissionDef(
            name="can_view",
            rewrite=UnionRule(children=(
                ComputedUsersetRule("owner"),
                ComputedUsersetRule("viewer"),
            )),
        ),
    ),
)

registry = SchemaRegistry()
registry.register_many((user_ns, doc_ns))

client = ZanzibarClient(
    schema=registry,
    relations_repository=InMemoryRelationRepository(),
)

# Write some tuples
client.write("document:readme", "owner", "user:alice")
client.write("document:readme", "viewer", "user:bob")

# Check
assert client.check("document:readme", "can_view", "user:alice") is True
assert client.check("document:readme", "can_view", "user:bob") is True
assert client.check("document:readme", "can_view", "user:eve") is False

For a more complete, fun-but-enterprise example (folders, documents, groups, tuple-to-userset), see examples/boobledrive.py.

How it works (at a glance)

  • Define namespaces with RelationDef and PermissionDef using rewrite rules.
  • Register them in SchemaRegistry (validated on registration).
  • Store relation tuples via the client (your storage backend implements the repo interface).
  • Evaluate checks using the rules-aware engine (with cycle detection and depth limits).

Roadmap / TODOs

  • Caching layer (read-through and check-result memoization) ⚡
  • Storage backends (example Postgres/SQLite adapters)
  • More examples (nested folders, exclusion/intersection patterns)
  • Packaging and versioned releases (PyPI)
  • Developer docs (schema patterns, migration tips)
  • Benchmarks and profiling harness
  • In-memory repositories for relations and rules
  • Core rewrite rules (union, intersection, exclusion, tuple-to-userset)
  • Registry validation of schemas

Bring your own persistence 🧱

You don’t run a server for zanzipy. Implement the lightweight repository interfaces and you’re done:

  • RelationRepository: store/read relation tuples.
  • RulesRepository (optional): provide rewrites at runtime; schema remains the source of truth if omitted.

See the in-memory implementations under src/zanzipy/storage/repos/concrete/memory as a reference.

License

Apache-2.0

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

zanzipy-0.1.1.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

zanzipy-0.1.1-py3-none-any.whl (37.7 kB view details)

Uploaded Python 3

File details

Details for the file zanzipy-0.1.1.tar.gz.

File metadata

  • Download URL: zanzipy-0.1.1.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.1

File hashes

Hashes for zanzipy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1c1438eb2f7f646cb4ba7434ee52dec4e4509e278db56044ee47befd62482a11
MD5 032da1fee26263d300c3707f8c8b0c7e
BLAKE2b-256 8ee3d808beddfa07235e2c5bab77176fd13b6d89c93285df3abd4969ac253642

See more details on using hashes here.

File details

Details for the file zanzipy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: zanzipy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.1

File hashes

Hashes for zanzipy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 39c36f24a43295c2df96885cf4adab976db79d5ed2f0b6b49188eb8fb62346fe
MD5 86b8a859836659ef7205b10bfbaaa605
BLAKE2b-256 a1435091551493d502a96c6aa651ef26692597d3f41b1cf4f7023cf653e6bd6a

See more details on using hashes here.

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