Skip to main content

Flask-RPBAC

Test status Code coverage PyPI version

Flask-RPBAC is a lightweight Flask authorization extension for expressing role-based and permission-based access control in a clean, composable way. It is designed for applications that need explicit access checks without turning authorization logic into a large set of ad hoc conditionals.

For the full documentation, including installation, quick start, API reference, and examples, please see the project docs on Read the Docs: https://flask-rpbac.readthedocs.io/en/latest/

The library supports:

  • role-based access checks

  • permission-based access checks

  • combined authorization rules with All and Any

  • composable requirement objects using & and | operators

  • blueprint-level protection alongside route-level protection

  • loader callbacks for roles, permissions, and user data

What it does

Flask-RPBAC lets you define authorization rules in a declarative style and apply them to Flask routes or entire blueprints. This keeps access decisions readable, testable, and easy to evolve as an application grows.

Typical use cases include:

  • restricting admin-only endpoints

  • enforcing permission checks for resource actions

  • combining role and permission requirements for complex policies

  • protecting blueprint sections with general access rules while keeping route-specific rules

Quick example

from flask import Flask
from flask_login import current_user
from flask_rpbac import RPBAC, Role, Permission, All, Any

app = Flask(__name__)
rpbac = RPBAC(app)

@rpbac.role_loader
def load_roles():
    return ["admin", "editor"] if current_user.is_authenticated else []

@rpbac.permission_loader
def load_permissions():
    return ["post:read", "post:write"] if current_user.is_authenticated else []

@app.route("/admin")
@rpbac.role_required(Role("admin"))
def admin_panel():
    return "Admin panel"

@app.route("/publish")
@rpbac.required(All(Role("editor"), Permission("post:write")))
def publish_post():
    return "Publish"

@app.route("/shared")
@rpbac.required(Any(Role("admin"), Permission("post:read")))
def shared_view():
    return "Shared view"

Installation

Install the package with pip:

pip install flask_rpbac

Requirements

Flask-RPBAC targets modern Flask applications and is designed for Flask 3.1 and newer, with Python 3.12+ support.

Contributing

Contributions are welcome. Please read the full contribution guide before opening a pull request.

We encourage pull requests, issue reports, and improvements to documentation, tests, and access control examples. A healthy contribution workflow is:

  • open an issue or discussion for larger changes

  • keep changes focused and easy to review

  • add or update tests for behavior changes

  • keep the public API clear and consistent

  • update documentation when user-facing behavior changes

  • follow the project coding and testing standards already in place

Before submitting changes, please run the project test suite and ensure the relevant checks pass. If you are improving behavior, add a regression test so the change is protected in the future.

Useful contributor resources:

Before submitting a change, contributors should have Python 3.12 or newer, create a virtual environment, install the development dependencies, and verify the project locally:

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest
tox

Please report security vulnerabilities privately through the process described in the Security Policy, rather than opening a public issue.

License

This project is distributed under the terms of the repository’s license.

Metadata

Release files for Flask-RPBAC 0.2.0

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

Source distribution (sdist)

Source distribution for Flask-RPBAC 0.2.0
File Size Uploaded Provenance
flask_rpbac-0.2.0.tar.gz 17.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-RPBAC 0.2.0
File Interpreter ABI Platform
flask_rpbac-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.7 kB

Release files / flask_rpbac-0.2.0.tar.gz

Download URL flask_rpbac-0.2.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
146832f2a388e09c2a3c00877048f31822b63bdf440f4c6845a7f2a5841fce4b
BLAKE2b-256 checksum
How to use checksums
afe8cd423440e94083d07ddb27889790bf87fd32402ce34842c3011534979b08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / flask_rpbac-0.2.0-py3-none-any.whl

Download URL flask_rpbac-0.2.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87b743b51e1004932c0d53dc771a578e08955ebe362ed770e7e7c639051dfa8d
BLAKE2b-256 checksum
How to use checksums
8ad441678abd19d91bc4be64f3d4fbc48b1c6eab5d9403ca5ee7a83c2493a436
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Security for Flask-RPBAC 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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