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.3.tar.gz (51.5 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.3-py3-none-any.whl (57.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vexen_rbac-0.1.3.tar.gz
  • Upload date:
  • Size: 51.5 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.3.tar.gz
Algorithm Hash digest
SHA256 d140d1758714fe2c570de168ba5cd0883b3b983ed576a1614af301ae59508bd3
MD5 d7ebb542b69280c16306f014a03791a5
BLAKE2b-256 433f7c69457ceea9cdef8c6bee712ab84e7e175d4af65c84acebec841395362e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: vexen_rbac-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 57.0 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c5cbcf7cab73c8cd00515c23ebf1850d9cb4680518dc70b54000ce3e99e7647b
MD5 70f07e58a11557d33aae0e650fbb4bd4
BLAKE2b-256 838fa5a31fcb850ee66feabb36d4f1359ca116e770f6ea7c896873b351e5bcc7

See more details on using hashes here.

Provenance

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