Skip to main content

Unified Permission Registry (UPR) for Django & DRF

Project description

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

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:

Requirements

  • Python 3.8+
  • Django 3.2+
  • Django REST Framework 3.12+

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_permission_engine-0.1.3.tar.gz (30.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_permission_engine-0.1.3-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file django_permission_engine-0.1.3.tar.gz.

File metadata

  • Download URL: django_permission_engine-0.1.3.tar.gz
  • Upload date:
  • Size: 30.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for django_permission_engine-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5a91294bc878984635f97a1f9c9f10dc2ab60866e5ede54b435778075ff22cdc
MD5 23a88f5a7518b44c011b6570bf28475d
BLAKE2b-256 03f70571b7392df693948603f7d9b8b977ce18dd55377e60c86b1dd8b6d7a98d

See more details on using hashes here.

File details

Details for the file django_permission_engine-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_permission_engine-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 562cab751291c045bd2f33f192fc6b30454e63286a32c41cb8cd96ddc25c38d1
MD5 24d32fc7e214b800327bd1310042ccfd
BLAKE2b-256 298b0fc2dfbd39028d5913eb52c25e34d87836e8b7a882a6cb62dbf970956f8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page