This release is a pre-release and may not be stable for production use.
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_rpbac-0.1.dev1.tar.gz.
File metadata
- Download URL: flask_rpbac-0.1.dev1.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccc8919a5b4494738cc07f915a80f1ce7a645f7938a8ea7192ff1ce77912cf7f
|
|
| MD5 |
eb8c6b080e48aefa4d37d3f503c27514
|
|
| BLAKE2b-256 |
95ba1d9e1c2cc29dcade1e07809288aaff159e7236f0bee3c0a5f3b3a7cdb282
|
File details
Details for the file flask_rpbac-0.1.dev1-py3-none-any.whl.
File metadata
- Download URL: flask_rpbac-0.1.dev1-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
040fb6416a75e26b343c63e6a17c4e58a33dd1ffed0e21a35495cdb5a3ab7acd
|
|
| MD5 |
a59804dba4a2b14fedcd13eda7199f62
|
|
| BLAKE2b-256 |
aec0bc4462f7ff3f3ae8dda4de4e1e390c704765ecb7c48bd8c64715f3de0f1b
|