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, Any, and Not

  • request- and object-level checks with Predicate

  • 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, Not, Predicate

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"

@app.route("/not-admin")
@rpbac.required(Not(Role("admin")))
def not_admin_view():
    return "Non-admin 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.3.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.3.0
File Size Uploaded Provenance
flask_rpbac-0.3.0.tar.gz 26.1 kB With provenance Details

Built distribution (wheel)

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

Total release size: 42.4 kB

Release files / flask_rpbac-0.3.0.tar.gz

Download URL flask_rpbac-0.3.0.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9944ae658324707f5a1992474349a1acee62d095102ad177ffab129c98546ab0
BLAKE2b-256 checksum
How to use checksums
dda9ccabdde34406af946bdcdf9c4b1329aa28b6ee3c46decb152ee576621bb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

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

Download URL flask_rpbac-0.3.0-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc0d5bd416d005a038cd5af16c896245ccddd0b7c61713222729ff6e1a6051da
BLAKE2b-256 checksum
How to use checksums
734a330af0e985f60412f7395de4841c6699d0d4db5249f0ef77789ab2cc5a81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Security for Flask-RPBAC 0.3.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for flask_rpbac-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

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