Skip to main content

django-clearance

Role, policy and row-level access control for Django. Denied by default.

فارسی

An administrator decides, in Django's admin site and with no code, who may do what - and to which rows, and with which fields:

  • bundles of permissions, each given with a scope - "their branch's orders", "their own", or a rule built in the admin site;
  • protected fields, read with one permission and written with another;
  • status actions - only whoever may approve sets an order to approved;
  • roles, optional, with a ceiling nobody with the role goes past.

Every door asks the same rules: Django's views and templates, DRF, the admin site, and your own code. A change is refused when it would let somebody give themselves more. The pages, messages and permissions come in English and Persian, and read right to left in Persian.

In a project

pip install 'django-clearance[drf]'
INSTALLED_APPS = [
    'clearance.admin.apps.ClearanceAdminConfig',   # instead of 'django.contrib.admin'
    ...
    'clearance',
]

AUTHENTICATION_BACKENDS = ['clearance.backends.ClearanceBackend']

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': ['clearance.drf.permissions.ModelPolicyPermission'],
}
class OrderViewSet(ScopedModelViewSet):  # the rows, the policy, the fields - asked
    queryset = Order.objects.all()
    serializer_class = OrderSerializer


Order.objects.visible_to(user, 'edit')  # the orders this person may edit

Python 3.11 to 3.14; Django 5.2, 6.0 and 6.1; Django REST framework 3.16 and later, optional; any database Django supports.

Working on it

Every check runs through nox, the same sessions locally and in CI. With uv installed, a Python that is missing is fetched for you.

uv tool install nox
nox -s lint
nox -s types
nox -s tests

tests runs every supported Python and Django; one combination is nox -s "tests(3.13-django6.1)", and nox -l lists them all. browser runs the pages in a real browser, messages - with gettext installed - checks that the catalogues hold every string the library marks, and package builds the wheel and runs the example project on it.

The suite uses SQLite unless told otherwise. To run it on PostgreSQL, as CI does, set CLEARANCE_TEST_DATABASE=postgres; the connection is read from the standard PGHOST, PGPORT, PGUSER, PGPASSWORD and PGDATABASE variables (defaults: localhost, 5432, postgres, postgres, clearance).

CLEARANCE_TEST_DATABASE=postgres nox -s tests

After marking a string, extract it with nox -s messages, translate what it added in locale/fa/LC_MESSAGES/django.po, and compile:

cd src/clearance && django-admin compilemessages

Licence

BSD 3-Clause - see LICENSE.

Metadata

Release files for django-clearance 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-clearance 0.2.0
File Size Uploaded Provenance Actions
django_clearance-0.2.0.tar.gz 309.7 kB With provenance Details for django_clearance-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-clearance 0.2.0
File Interpreter ABI Platform Actions
django_clearance-0.2.0-py3-none-any.whl Python 3 none any Details for django_clearance-0.2.0-py3-none-any.whl

Total release size: 500.1 kB

Release files / django_clearance-0.2.0.tar.gz

Download URL django_clearance-0.2.0.tar.gz
Size 309.7 kB
Tags Source
SHA-256 checksum
How to use checksums
674c695a6051cedfbb99e99f8a334710baa0655ef9533f69032b3d9c76f0f804
BLAKE2b-256 checksum
How to use checksums
414301f1cd596e1d98be1c4e930746a2497ea9de8e51f5d968eff28ef1e327c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / django_clearance-0.2.0-py3-none-any.whl

Download URL django_clearance-0.2.0-py3-none-any.whl
Size 190.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba22d959a8a52296b8099fd376af5ffe03869f8e141714c5004369b9191adeef
BLAKE2b-256 checksum
How to use checksums
682ada9d0708aaee7ff0f429e390b065a4441f2d3753564d313215bd677d9a7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for django-clearance 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_clearance-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page