Skip to main content

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 vexen_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

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.

Metadata

Release files for vexen-rbac 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vexen-rbac 0.1.4
File Size Uploaded Provenance
vexen_rbac-0.1.4.tar.gz 55.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for vexen-rbac 0.1.4
File Interpreter ABI Platform
vexen_rbac-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 113.4 kB

Release files / vexen_rbac-0.1.4.tar.gz

Download URL vexen_rbac-0.1.4.tar.gz
Size 55.6 kB
Tags Source
SHA-256 checksum
How to use checksums
40b6d8223359a2d15a0e91af9d781bd32ac79a629258b9f817be517f8831a46d
BLAKE2b-256 checksum
How to use checksums
5d3e6b6324c22492285df88d786df3663adb2057ddcb6cee720e3b4d5890d6b9
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 Dec 3, 2025.

Transparency log

Release files / vexen_rbac-0.1.4-py3-none-any.whl

Download URL vexen_rbac-0.1.4-py3-none-any.whl
Size 57.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a0a53b0697b8109b4e89ea6ccc4190057963b5636aa6d3fc6d2f9941309a6dd
BLAKE2b-256 checksum
How to use checksums
e0132b1b490393ad925a6764278b4b5fac3b0e602792edafed7eaf59c9c72b13
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 Dec 3, 2025.

Transparency log

Security for vexen-rbac 0.1.4

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vexen_rbac-0.1.4.tar.gz

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 Dec 3, 2025.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page