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

**URL:** <https://forum.djangoproject.com/t/permissions-that-commit-in-the-same-transaction-atomic-as-your-models/46306>\
**Category:** Show & Tell\
**Created:** [October 28, 2026, 3:30pm UTC](https://forum.djangoproject.com/t/permissions-that-commit-in-the-same-transaction-atomic-as-your-models/46306 "2026-10-28T15:30:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joshua-Fields](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/joshua-fields/32/33619_2.png) [@Joshua-Fields](https://forum.djangoproject.com/u/Joshua-Fields)\
**Post date:** [October 28, 2026, 3:30pm UTC](https://forum.djangoproject.com/t/permissions-that-commit-in-the-same-transaction-atomic-as-your-models/46306/1 "2026-10-28T15:30:45Z")

</div>

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:

```python
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](https://github.com/Joshua-Fields/pemba)

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
