Permissions that commit in the same transaction.atomic() as your models

Hi all,

Every time I’ve used an external permissions service, I’ve ended up writing an outbox to keep it in sync with the database. You create a document, grant access in a separate system, and if anything fails in between the two drift apart.

So I built a small open-source library, pemba, that keeps the permission tables in your own Postgres database instead. The permission write joins your transaction:

from django.db import transaction, connection

with transaction.atomic():
    doc = Document.objects.create(title="Q4 roadmap")
    engine.write(touch=[f"document:{doc.pk}#owner@user:{user.pk}"], conn=connection)
    # if anything raises, the document and the permission both roll back

engine.check(f"document:{doc.pk}", "view", f"user:{user.pk}")    # True
engine.lookup_resources("document", "view", f"user:{user.pk}")   # which documents can they see?

It handles Google Docs-style sharing (groups, folders, inheritance, exclusions), with permissions defined in a small schema language. It also works with SQLite.

It’s an early alpha (pip install --pre pemba), so there are rough edges. One I know about: Django’s TestCase triggers a harmless pemba warning after each test, which is documented and can be filtered.

Repo: GitHub - Joshua-Fields/pemba: Embedded Zanzibar-style authorization for Rust and Python. Permission writes that join your app's own Postgres or SQLite transaction. · GitHub

I’d really like to hear how people here handle object-level permissions today (django-guardian, rules, something custom), and what a proper Django integration would need to feel natural.

Thanks,
Joshua