Skip to main content

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

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


Download files

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

Source Distribution

vexen_rbac-0.1.0.tar.gz (51.1 kB view details)

Uploaded Source

Built Distribution

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

vexen_rbac-0.1.0-py3-none-any.whl (55.1 kB view details)

Uploaded Python 3

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

Hashes for vexen_rbac-0.1.0.tar.gz
Algorithm Hash digest
SHA256 44eb89b16ef01c5d06338bbcffe051b4ba8707973ffcf1db01617d91e246051e
MD5 2501480471050cf56393c8f58220b04c
BLAKE2b-256 b247cef1cfd5900de5b9ec4b1626ddd99f5f9ea0dbb8d46a49fb566b59ef576a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vexen_rbac-0.1.0.tar.gz:

Publisher: python-publish.yml on vexen-labs/vexen-rbac

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for vexen_rbac-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c10c70a84fa0b282e4ca28ff63dca0fa131674121a05ab1d69b494c584e01562
MD5 3de0470787a4497e02e6999ea3029b69
BLAKE2b-256 7d53fc3eb51ec3e3828e6bf45823010ca48282526fe987280c16910f21cf1ca7

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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