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

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.4.tar.gz (55.6 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.4-py3-none-any.whl (57.9 kB view details)

Uploaded Python 3

File details

Details for the file vexen_rbac-0.1.4.tar.gz.

File metadata

  • Download URL: vexen_rbac-0.1.4.tar.gz
  • Upload date:
  • Size: 55.6 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.4.tar.gz
Algorithm Hash digest
SHA256 40b6d8223359a2d15a0e91af9d781bd32ac79a629258b9f817be517f8831a46d
MD5 344e0a970bd53e4613a2194bd098732f
BLAKE2b-256 5d3e6b6324c22492285df88d786df3663adb2057ddcb6cee720e3b4d5890d6b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for vexen_rbac-0.1.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: vexen_rbac-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 57.9 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9a0a53b0697b8109b4e89ea6ccc4190057963b5636aa6d3fc6d2f9941309a6dd
MD5 addba2acdd250b7cb0a0b996faa34c29
BLAKE2b-256 e0132b1b490393ad925a6764278b4b5fac3b0e602792edafed7eaf59c9c72b13

See more details on using hashes here.

Provenance

The following attestation bundles were made for vexen_rbac-0.1.4-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