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, package builds the wheel and runs the example project on it, and docs builds the documentation site - nox -s docs -- serve shows it as it is written. screenshots takes the site's pictures of the admin site again, from the example project.

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.1

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.1
File Size Uploaded Provenance Actions
django_clearance-0.2.1.tar.gz 2.9 MB With provenance Details for django_clearance-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 3.0 MB

Release files / django_clearance-0.2.1.tar.gz

Download URL django_clearance-0.2.1.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
97bd986c8f5434ecc787c5da47d473c84c44cd50152e0ced1273b864a51ab555
BLAKE2b-256 checksum
How to use checksums
b021a26650d0e120f343d4b7c083c1d933ba55853b6c1c176be08332d40e6978
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 14, 2026.

Transparency log

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

Download URL django_clearance-0.2.1-py3-none-any.whl
Size 193.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c98b07bb06cae8c18e0404d020d39a2a746843736dbd5f1f3698a97e266139ac
BLAKE2b-256 checksum
How to use checksums
dd0820766266c78b8dc56987fc5587f2fef6228eafdefaeef44c78ba828f2417
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 14, 2026.

Transparency log

Security for django-clearance 0.2.1

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.1.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 14, 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