Permission Manager
A simple way to manage object permissions.
Full documentation on read the docs.
Install
pip install permission-manager
Example
Use BasePermissionManager
import dataclasses
from permission_manager import BasePermissionManager, PermissionResult
@dataclasses.dataclass
class User:
name: str
@dataclasses.dataclass
class Person:
first_name: str
last_name: str
status: str
class PersonPermissionManager(BasePermissionManager):
instance: Person
def has_create_permission(self):
return True
def has_delete_permission(self):
return self.user.name == 'admin'
def has_access_permission(self):
if self.instance.status == 'excommunicado':
return PermissionResult('Due status')
return True
manager = PersonPermissionManager()
manager.has_permission('create')
# same as
# manager.has_create_permission()
# > True
manager = PersonPermissionManager(
instance=Person(
first_name='John',
last_name='Wick',
status='excommunicado',
),
user=User(name='Ms. Perkins'),
)
manager.has_permission('delete')
# > False
manager.has_permission('access')
# > PermissionResult(value=False, message=['Due status'])
manager.resolve(actions=('access', 'create', 'delete'))
# > {'access': False, 'create': True, 'delete': False}
manager.resolve(actions=('access', 'create', 'delete'), with_messages=True)
# > {'access': {'allow': False, 'messages': ['Due status']},
# 'create': {'allow': True, 'messages': None},
# 'delete': {'allow': False, 'messages': None}}
Also, it's include PermissionManager, which add additional functionality to check parent permissions
import dataclasses
from permission_manager import PermissionManager
class PostPermissionManager(PermissionManager):
instance: 'Post'
def has_update_permission(self):
return self.instance.status == 'draft'
@dataclasses.dataclass
class Post:
title: str
status: str = 'draft'
permission_manager = PostPermissionManager
class ImagePermissionManager(PermissionManager):
parent_attr = 'post'
instance: 'Image'
def has_update_permission(self):
return self.parent_permission_manager.has_permission('update')
@dataclasses.dataclass
class Image:
post: Post
file: str
post = Post(title='Test')
manager = ImagePermissionManager(
instance=Image(
post=post,
file='/path/to/file',
),
)
manager.has_permission('update')
# > True
post.status = 'published'
manager.has_permission('update')
# > False
Async
import asyncio
from permission_manager import AsyncBasePermissionManager
class AsyncManager(AsyncBasePermissionManager):
async def has_create_permission(self) -> bool:
# Some IO bound operations here
return True
async def main():
manager = AsyncManager()
result = await manager.has_permission('create')
print(result)
asyncio.run(main())
Metadata
Release files for permission-manager 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| permission_manager-0.6.1.tar.gz | 46.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| permission_manager-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.6 kB
Release files / permission_manager-0.6.1.tar.gz
| Download URL | permission_manager-0.6.1.tar.gz |
|---|---|
| Size | 46.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ceb2a50389f6ddd0920b1b3c63583f3fdaa96b5744b82883127f4e0c1f7f5661
|
|
BLAKE2b-256 checksum How to use checksums |
4f92b355de63adaa674876626c410287ad7999f2b2705f605040fcd4c02bf477
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.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.
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 Jan 13, 2026.
Transparency logRelease files / permission_manager-0.6.1-py3-none-any.whl
| Download URL | permission_manager-0.6.1-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38a799c42ce470e6710b0e1bbbd14a47de0bce79c437bf9302ab7d83d7f438d2
|
|
BLAKE2b-256 checksum How to use checksums |
ea8b622fe6b91c998c632fb1e5263336ac1009ddc0a9dd3db70b3e32188df4d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.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.
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 Jan 13, 2026.
Transparency log