Registry / security / django-prbac

django-prbac

JSON →
library1.1.2pypypiunverified

Parameterized Role-Based Access Control for Django. Provides hierarchical roles with customizable parameters (e.g., plan limits), integrates with Django admin, and supports migrations. Current version: 1.1.2. Release cadence: infrequent, last updated in 2021.

pip install django-prbac
INSTALL
IMPORT
SIG · DJANGO-PRBAC
D
django-prbac
securitypythonv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

PrbacRole
✓ from django_prbac.roles import PrbacRole
✗ from prbac.roles import PrbacRole

Minimal setup: add 'prbac' to INSTALLED_APPS, run migrations, then use PrbacRole and decorators.

# settings.py INSTALLED_APPS = [ 'django.contrib.contenttypes', 'django.contrib.auth', 'prbac', # ... other apps ] # Run migrations: python manage.py migrate prbac # Then in code: from prbac.roles import PrbacRole role = PrbacRole('plan:pro') # Check permission user.has_perm('prbac.access_role', obj=role) # Or use decorator from prbac.decorators import requires_privilege @requires_privilege('plan:pro') def my_view(request): return HttpResponse('ok')
Debug
Known issues
gotchaThe 'requires_privilege' decorator checks against the request.user's roles, but the user model must have a 'get_roles()' method. If you have a custom user model, ensure it implements this method.
fix
Add a 'get_roles()' method to your user model that returns a list of PrbacRole objects.
affects: all
deprecatedThe 'jsonfield' dependency is deprecated and may cause compatibility issues with newer Django versions. Consider using Django's built-in JSONField.
fix
Monkey-patch or fork to replace jsonfield with Django's JSONField. No official migration path provided.
affects: >=1.1.0
gotchaRoles are defined in data, not code. After changing role permissions via Django admin, you must run 'manage.py sync_couch_views' if using CouchDB backend, otherwise role changes are not effective until restart.
fix
Restart your Django app after role changes, or use the appropriate sync command for your backend.
affects: all
Upgrade
Version history
1.1.2latest on PyPI · released Sep 24, 2025
Audit
Dependencies
djangorequiredCore dependency
jsonfieldrequiredUsed for storing role parameter schemas
sixoptionalUsed for Python 2/3 compatibility, but may be redundant with Python 3.9+
Agent activity
19 hits · last 30 days
node
18
Resources