Role-Based Access Control library with hexagonal architecture
Project description
RBAC - Role-Based Access Control Library
A flexible and extensible Role-Based Access Control (RBAC) library built with hexagonal architecture principles, designed to be as simple to use as FastAPI.
Features
- Clean Architecture: Built with hexagonal architecture (ports and adapters)
- Simple API: FastAPI-like interface for ease of use
- Async Support: Fully asynchronous using SQLAlchemy 2.0+ with asyncpg
- Type Safe: Complete type hints for better IDE support
- Flexible: Easy to extend and customize
- Production Ready: Session management, connection pooling, and error handling
Installation
pip install rbac
Or with uv:
uv pip install rbac
Quick Start
from rbac import RBAC
from rbac.application.dto import CreateRoleRequest
# Initialize RBAC
rbac = RBAC(database_url="postgresql+asyncpg://user:pass@localhost/db")
await rbac.init()
# Create a role
role = await rbac.roles.create_role(
CreateRoleRequest(
name="admin",
display_name="Administrator",
permissions=[1, 2, 3]
)
)
# List roles with pagination
result = await rbac.service.list_roles_paginated(page=1, page_size=20)
# Get role with expanded permissions
role_detail = await rbac.service.get_role_expanded(role_id=1)
# Close when done
await rbac.close()
Usage with FastAPI
from fastapi import FastAPI
from rbac import RBAC
app = FastAPI()
rbac = RBAC(database_url="postgresql+asyncpg://...")
@app.on_event("startup")
async def startup():
await rbac.init()
@app.on_event("shutdown")
async def shutdown():
await rbac.close()
@app.get("/roles")
async def list_roles(page: int = 1, page_size: int = 20):
result = await rbac.service.list_roles_paginated(page, page_size)
return result
Features
Roles
- Create, read, update, delete roles
- List roles with pagination
- Add/remove permissions from roles
- Count roles and permissions
Permissions
- Create, read, update, delete permissions
- List permissions
- Group permissions by category
Permission Groups
- Create, read, update, delete permission groups
- Add/remove permissions from groups
- Organize permissions hierarchically
Architecture
This library follows hexagonal architecture principles:
- Domain Layer: Pure business logic (entities, value objects)
- Application Layer: Use cases and DTOs
- Infrastructure Layer: Database adapters (SQLAlchemy)
- Public API: Clean facade hiding complexity
Requirements
- Python 3.11+
- PostgreSQL (with asyncpg)
- SQLAlchemy 2.0+
Documentation
- Usage Guide - Complete usage documentation
- API Examples - API response formats
- Integration Guide - Framework integration examples
- New Features - Recently added features
Development
# Clone repository
git clone https://github.com/yourusername/rbac.git
cd rbac
# Install with development dependencies
uv pip install -e ".[dev]"
# Run tests
pytest
# Format code
ruff format .
# Lint code
ruff check .
License
MIT License - see LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and questions, please open an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vexen_rbac-0.1.0.tar.gz.
File metadata
- Download URL: vexen_rbac-0.1.0.tar.gz
- Upload date:
- Size: 51.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44eb89b16ef01c5d06338bbcffe051b4ba8707973ffcf1db01617d91e246051e
|
|
| MD5 |
2501480471050cf56393c8f58220b04c
|
|
| BLAKE2b-256 |
b247cef1cfd5900de5b9ec4b1626ddd99f5f9ea0dbb8d46a49fb566b59ef576a
|
Provenance
The following attestation bundles were made for vexen_rbac-0.1.0.tar.gz:
Publisher:
python-publish.yml on vexen-labs/vexen-rbac
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vexen_rbac-0.1.0.tar.gz -
Subject digest:
44eb89b16ef01c5d06338bbcffe051b4ba8707973ffcf1db01617d91e246051e - Sigstore transparency entry: 731874983
- Sigstore integration time:
-
Permalink:
vexen-labs/vexen-rbac@01f8330c9c8c341ff8c2ecdfa57c8831fbfb4402 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/vexen-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@01f8330c9c8c341ff8c2ecdfa57c8831fbfb4402 -
Trigger Event:
release
-
Statement type:
File details
Details for the file vexen_rbac-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vexen_rbac-0.1.0-py3-none-any.whl
- Upload date:
- Size: 55.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c10c70a84fa0b282e4ca28ff63dca0fa131674121a05ab1d69b494c584e01562
|
|
| MD5 |
3de0470787a4497e02e6999ea3029b69
|
|
| BLAKE2b-256 |
7d53fc3eb51ec3e3828e6bf45823010ca48282526fe987280c16910f21cf1ca7
|
Provenance
The following attestation bundles were made for vexen_rbac-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on vexen-labs/vexen-rbac
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vexen_rbac-0.1.0-py3-none-any.whl -
Subject digest:
c10c70a84fa0b282e4ca28ff63dca0fa131674121a05ab1d69b494c584e01562 - Sigstore transparency entry: 731874984
- Sigstore integration time:
-
Permalink:
vexen-labs/vexen-rbac@01f8330c9c8c341ff8c2ecdfa57c8831fbfb4402 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/vexen-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@01f8330c9c8c341ff8c2ecdfa57c8831fbfb4402 -
Trigger Event:
release
-
Statement type: