Building blocks for zanzibar style ReBAC
Project description
zanzipy ✨
Zanzibar‑style authorization for Python, with a tiny DSL to declare your schema and a simple client to write and check permissions. Friendly, lightweight, and practical.
Install 📦
pip install zanzipy
Quick start 🚀
from zanzipy.dsl.builder import SchemaBuilder
from zanzipy.client import ZanzibarClient
from zanzipy.storage.repos.concrete.memory.relations import InMemoryRelationRepository
# Define schema with the fluent DSL
registry = (
SchemaBuilder()
.namespace("user").done()
.namespace("document")
.relation("owner", subjects=["user"]) # direct
.permission("can_view", union=["owner"]) # computed
.done()
.build()
)
# Use the in‑memory repo for a zero‑dependency start
client = ZanzibarClient(schema=registry, relations_repository=InMemoryRelationRepository())
client.write("document:readme", "owner", "user:alice")
assert client.check("document:readme", "can_view", "user:alice")
That’s it. Add more relations/permissions with the DSL, and swap the repository when you’re ready to plug in your storage.
See the examples/ folder 📁 for more patterns (tuple‑to‑userset, groups, nested folders). A good starting point is examples/document_drive.py.
Quick start with mixins 🧩
Zanzipy also provides convenient mixins for Pythonic integration with your domain models.
from dataclasses import dataclass
from zanzipy.client import ZanzibarClient
from zanzipy.dsl.builder import SchemaBuilder
from zanzipy.engine_integration import ZanzibarEngine, configure_authorization
from zanzipy.integration.mixins import AuthorizableResource, AuthorizableSubject
from zanzipy.storage.repos.concrete.memory.relations import InMemoryRelationRepository
# Define a minimal schema (user + document)
registry = (
SchemaBuilder()
.namespace("user").done()
.namespace("document")
.relation("owner", subjects=["user"]) # direct relation
.permission("can_view", union=["owner"]) # computed permission
.done()
.build()
)
# Wire up the engine used by the mixins
client = ZanzibarClient(schema=registry, relations_repository=InMemoryRelationRepository())
configure_authorization(ZanzibarEngine(client))
# Domain models using mixins
@dataclass
class User(AuthorizableSubject):
id: str
def get_subject_dict(self) -> dict:
return {"namespace": "user", "id": self.id}
@dataclass
class Document(AuthorizableResource):
id: str
def get_resource_dict(self) -> dict:
return {"namespace": "document", "id": self.id}
# Use high‑level helpers
alice = User(id="alice")
readme = Document(id="readme")
readme.grant(alice, "owner") # writes a tuple: document:readme#owner@user:alice
assert readme.check(alice, "can_view") # True via the computed permission
For a fuller mixins setup with groups, SQLAlchemy models, and caching, see examples/document_drive_sqlalchemy_and_mixins.py.
Key features 🧰
- ✨ DSL‑first schema authoring (
SchemaBuilder,NamespaceBuilder). - 🔗 Zanzibar semantics: relations, permissions, union/intersection/exclusion, tuple‑to‑userset.
- ✅ Correctness‑first evaluation: cycle detection, max‑depth limits, and subject expansion.
- 🧩 Simple client API:
write,delete,check,list_objects,expand. - 🗄️ Storage‑agnostic: implement
RelationRepository; start with in‑memory. - ⚡ Optional caching: tuple cache and compiled rule cache for hot paths.
When should you use zanzipy? 🤔
- You want ReBAC embedded in your Python app without running another service.
- You prefer a human‑readable, declarative schema (via a tiny DSL).
- Your app has shared resources (e.g., docs, folders, teams) and needs roles, groups, or nested access patterns.
- You need cross‑resource edges (tuple‑to‑userset) and clear, testable authorization logic.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zanzipy-0.1.4.tar.gz.
File metadata
- Download URL: zanzipy-0.1.4.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86c44f2e544ddc0e4dccb0b45146e0dbd4669293cdb989c3e0f61259b9713312
|
|
| MD5 |
5b0ba0725cd021911e8b7c7287cdd1d7
|
|
| BLAKE2b-256 |
561cd0932570d7186b71034189aff6424b9a389fc1c3fdb57f5300dc76ead718
|
Provenance
The following attestation bundles were made for zanzipy-0.1.4.tar.gz:
Publisher:
publish.yml on tylerchambers/zanzipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zanzipy-0.1.4.tar.gz -
Subject digest:
86c44f2e544ddc0e4dccb0b45146e0dbd4669293cdb989c3e0f61259b9713312 - Sigstore transparency entry: 1905541687
- Sigstore integration time:
-
Permalink:
tylerchambers/zanzipy@2103f41690c905941a7f8f1d29698788100c366e -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/tylerchambers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2103f41690c905941a7f8f1d29698788100c366e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file zanzipy-0.1.4-py3-none-any.whl.
File metadata
- Download URL: zanzipy-0.1.4-py3-none-any.whl
- Upload date:
- Size: 64.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4039cada4d368e228f5effce8f5125dc1f97a8aa8cda7493b5ddce536075a44a
|
|
| MD5 |
6b27a6421d3d75aa4e6bffe7d2aad55b
|
|
| BLAKE2b-256 |
d1bd05c0ede547374069904527ca3e30eb4d5b33b6a23d15480b1064577f443a
|
Provenance
The following attestation bundles were made for zanzipy-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on tylerchambers/zanzipy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zanzipy-0.1.4-py3-none-any.whl -
Subject digest:
4039cada4d368e228f5effce8f5125dc1f97a8aa8cda7493b5ddce536075a44a - Sigstore transparency entry: 1905541845
- Sigstore integration time:
-
Permalink:
tylerchambers/zanzipy@2103f41690c905941a7f8f1d29698788100c366e -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/tylerchambers
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2103f41690c905941a7f8f1d29698788100c366e -
Trigger Event:
workflow_dispatch
-
Statement type: