Django Permission Engine
Unified Permission Registry (UPR) for Django & DRF
Overview
Django Permission Engine provides a single-source, action-aware, declarative permission system for Django and Django REST Framework. It eliminates permission drift and provides a maintainable foundation for complex permission requirements.
Features
- 🎯 Single Source of Truth - Define permissions once, everything else is derived
- 🔑 Permission Keys - Simple, immutable, string-based permission identifiers
- 🎬 Action-Aware - DRF actions automatically map to permissions
- 📊 Frontend-Ready - Permission catalog API for frontend consumption
- 🚫 Drift Prevention - Startup validation ensures code and database never drift
- ⚡ Performance - O(1) permission checks with optional caching
- ✅ Opt-In Model - Only actions defined in UPR config require permissions; others are allowed
- 👥 User Groups - Assign permissions to groups, then assign users to groups; effective permissions = direct + group
Installation
pip install django-permission-engine
Note: This library uses flexible version requirements (minimum versions only) to avoid conflicts with your existing Django and DRF installations. It will work with any compatible version you already have installed.
Quick Start
1. Add to INSTALLED_APPS
INSTALLED_APPS = [
# ... other apps
'rest_framework',
'django_permission_engine',
]
2. Configure
UPR_CONFIG = {
'validate_on_startup': True,
'strict_mode': True,
'auto_sync': False,
}
3. Define Permissions
# upr_config.py
from django_permission_engine import module, action
@module('users', label='User Management')
class UsersModule:
crud = ['view', 'create', 'update', 'delete']
actions = ['reset_password']
4. Sync to Database
python manage.py upr_sync
5. Assign Permissions to Users
Use the Permission Management API (admin only):
# Assign permission to user
POST /api/permissions/users/1/assign/
{
"permission_key": "users.view"
}
# Bulk assign to multiple users
POST /api/permissions/bulk-assign/
{
"permission_keys": ["users.view", "users.create"],
"user_ids": [1, 2, 3]
}
Or programmatically:
from django_permission_engine.models import Permission, UserPermission
user = User.objects.get(username='john')
permission = Permission.objects.get(key='users.view')
UserPermission.objects.get_or_create(user=user, permission=permission)
6. Use in ViewSets
from rest_framework import viewsets
from django_permission_engine.permissions import PermissionRequired
class UserViewSet(viewsets.ModelViewSet):
permission_classes = [PermissionRequired]
module = 'users'
queryset = User.objects.all()
serializer_class = UserSerializer
Documentation
Full documentation is available in the docs/ folder:
- Architecture
- Core Concepts
- Permission Definition
- DRF Integration
- Opt-In Permissions - Understanding the opt-in permission model
- User Groups - Groups, UPRHelper (get_user_groups, direct/group/effective permission keys)
- API Reference
Requirements
- Python 3.8+
- Django 3.2+
- Django REST Framework 3.12+
License
MIT License
Metadata
Release files for django-permission-engine 0.1.7
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_permission_engine-0.1.7.tar.gz | 36.9 kB | Without provenance | Details for django_permission_engine-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_permission_engine-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for django_permission_engine-0.1.7-py3-none-any.whl |
Total release size: 68.1 kB
Release files / django_permission_engine-0.1.7.tar.gz
| Download URL | django_permission_engine-0.1.7.tar.gz |
|---|---|
| Size | 36.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e3a0197c34923ef938a1bf7bc8aa631cb7e015e0a7a62b8126909d194a69c79
|
|
BLAKE2b-256 checksum How to use checksums |
a493aa2bba141f285d74c84e52ab034f187543232396309dd6a944498c2054de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / django_permission_engine-0.1.7-py3-none-any.whl
| Download URL | django_permission_engine-0.1.7-py3-none-any.whl |
|---|---|
| Size | 31.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
add95255c9254180f1bbf0424f669ff724e933d255269c01111c938dbe7bbcd9
|
|
BLAKE2b-256 checksum How to use checksums |
51454adb01cec3e2fb7d35deebf7f9c4407ca26e9a3d0754c2261cbff9e5d1a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for django-permission-engine 0.1.7
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.