Registry / auth-security / casbin-django-orm-adapter

casbin-django-orm-adapter

JSON →
library1.7.0pypypiunverified

Django ORM adapter for PyCasbin, enabling Casbin permission management to store policies in Django models. Version 1.7.0 supports Python >=3.7 and Django 2.2+.

pip install casbin-django-orm-adapter
INSTALL
IMPORT
SIG · CASBIN-DJANGO-ORM-
C
casbin-django-orm-adapter
auth-securitypythonv1.7.0
Install
4.0s avg
Import
Disk
70MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 70.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.000s · 71MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Adapter
from casbin_adapter import Adapter
from casbin_django_orm_adapter.adapter import Adapter

Initialize Casbin enforcer with Django ORM adapter. Ensure Django is configured and settings module is set before use.

import os import django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project.settings') django.setup() import casbin from casbin_django_orm_adapter.adapter import Adapter adapter = Adapter() e = casbin.Enforcer('path/to/model.conf', adapter) # Check permission sub = 'alice' obj = 'data1' act = 'read' if e.enforce(sub, obj, act): print('Access granted') else: print('Access denied')
Debug
Known issues
breakingIn version 1.5.0, the Adapter initialization changed. adapter = Adapter() now requires model_conf to be passed to the Enforcer, not to the Adapter.
fix
Update to use Adapter() without arguments and pass model path to Enforcer.
affects: <1.5.0
gotchaThe adapter uses Django's ORM, so you must run migrations to create the casbin_rule table before using the adapter. Missing migration leads to table not found errors.
fix
Run 'python manage.py migrate casbin_django_orm_adapter' after adding the app to INSTALLED_APPS.
affects: all
deprecatedIn version 1.6.0, the Adapter no longer accepts 'model' argument in its constructor; it must be initialized empty.
fix
Use adapter = Adapter() (no arguments).
affects: <=1.5.0
Upgrade
Version history
1.7.0latest on PyPI · released Aug 20, 2025
Audit
Dependencies
djangorequiredrequired for ORM functionality
casbinrequiredcore authorization library
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
casbin-django-orm-adapter — pip install casbin-django-orm-adapter · libregistry