Skip to main content
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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_rpbac-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_rpbac-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file flask_rpbac-0.1.0.tar.gz.

File metadata

  • Download URL: flask_rpbac-0.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for flask_rpbac-0.1.0.tar.gz
Algorithm Hash digest
SHA256 76386d50bec9e0e07c38b5bc4238ec8e5b5b5e607c972572c0e5ca2a1877bf2e
MD5 c1387204d95b9a4c7db1dda91e6fce28
BLAKE2b-256 0d5944216a3e747917fc6c8607bad25127b1f4a150c7ac16c460959258050560

See more details on using hashes here.

File details

Details for the file flask_rpbac-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flask_rpbac-0.1.0-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

Hashes for flask_rpbac-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0549557da2807b1a2e90b0c8d4b08c11a535e819582bd75d05bbf25917fa886
MD5 c8a52bfc8c27e6ba29c4f0dfa9eea649
BLAKE2b-256 022a18dd159771018f40dffd3b7ac0a9ae8318688aea153230140ce48b815e24

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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