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
- The guide - every part, how to use it.
- The example shop - a project using all of it, to run.
- The design - why it is built the way it is.
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.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_clearance-0.1.0.tar.gz | 250.6 kB | With provenance | Details for django_clearance-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_clearance-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_clearance-0.1.0-py3-none-any.whl |
Total release size: 417.1 kB
Release files / django_clearance-0.1.0.tar.gz
| Download URL | django_clearance-0.1.0.tar.gz |
|---|---|
| Size | 250.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0a789c8295db7a0f2eb6faf10f58c62be0340ffe1feca093bbab2eaa24b5808
|
|
BLAKE2b-256 checksum How to use checksums |
2cadf95205d4b5af6b9776d3ccfcaf9211c0b77ba369e9da71826d5ed219ccf1
|
| 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 12, 2026.
Transparency logRelease files / django_clearance-0.1.0-py3-none-any.whl
| Download URL | django_clearance-0.1.0-py3-none-any.whl |
|---|---|
| Size | 166.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f681857036c25990568fbf343e67383b9eb2e684ea605493c3ecc9700fbe442
|
|
BLAKE2b-256 checksum How to use checksums |
c6d7bad7bd36654707b93bf10d4a020b159a4937b68be210adc9702f3cf6573e
|
| 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 12, 2026.
Transparency logSecurity for django-clearance 0.1.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.
Attestation for django_clearance-0.1.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 12, 2026.
Transparency logA 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.