django-zed-rebac: relationship-based permissions with strict queryset scoping (alpha)

Hi everyone,

I’m working on django-zed-rebac, an open-source package that brings relationship-based access control (ReBAC) to Django, using SpiceDB’s .zed schema language.

The idea is to express permissions through relationships: someone can read a document because they own it, belong to its team, or have access to its parent folder. The package evaluates those rules locally through Django queries, without a separate authorization service.

You declare a permissions.zed file alongside your app, add RebacMixin to the models you want to protect, and load the schema with python manage.py rebac sync.

For example, this schema fragment lets a document inherit read access from its folder, while reserving writes for its owner. It assumes the user and folder types are defined elsewhere:

definition drive/document {
    relation owner: auth/user
    relation folder: drive/folder // rebac:field=folder

    permission read = (owner + folder->read)
    permission write = owner
}

The folder relation reads the model’s existing Django foreign key. The owner relation is stored explicitly as a relationship.

Once the model and schema are configured, application code looks like:

# Only documents this user can read.
documents = Document.objects.with_actor(request.user)

document = documents.get(pk=document_id)
document.title = "Updated title"

# Checks write permission using the actor carried by the instance.
document.save()

A few design choices:

  • Strict scoping by default. Evaluating a protected queryset without an actor raises MissingActorError. An explicit sudo(reason="...") bypass is audited.
  • Permissions read your existing data. Declared relations can use Django fields and relationship tuples; permissions compile into database queries.
  • The actor is explicit outside HTTP too. The same with_actor() API works in background tasks and management commands.
  • Integrations are available for DRF, Strawberry GraphQL, and MCP tools. The package also supports caveats, expiring relationships, and admin-editable schema overrides.

It currently targets Python 3.14 and Django 6.1, with PostgreSQL as the production database target, and is licensed under Apache-2.0.

This is alpha software. There are documented ORM enforcement gaps being addressed toward 1.0, the automated conformance suite against SpiceDB is still planned, and performance at large scale hasn’t been verified. The architecture docs describe the current behavior and limits.

I’d appreciate feedback on the Django integration in particular: would explicit actor scoping fit your application, and which permission patterns or ORM operations would you need covered before trying it?