Skip to main content

Installation

Requirements

  • Python 3.10 or higher
  • FastAPI ≥ 0.115.0

Core package

Install the core package with pip:

pip install casbin-fastapi-decorator

Or with uv:

uv add casbin-fastapi-decorator

Optional extras

The core package is intentionally minimal. Install only what you need:

File-based policies with hot-reload

Adds CachedFileEnforcerProvider - caches the Casbin enforcer loaded from model.conf and policy.csv, and reloads it automatically when either file changes.

pip install "casbin-fastapi-decorator[file]"

JWT authentication

Adds JWTUserProvider — extracts and validates JWT tokens from Bearer headers or cookies.

pip install "casbin-fastapi-decorator[jwt]"

Database policies

Adds DatabaseEnforcerProvider - loads policies from a SQLAlchemy async session, caches the enforcer, and hot-reloads when model.conf or database rows change.

pip install "casbin-fastapi-decorator[db]"

Casdoor integration

Adds CasdoorIntegration and related helpers for Casdoor OAuth2 login, cookie-based authentication, and remote policy enforcement.

pip install "casbin-fastapi-decorator[casdoor]"

Install everything

pip install "casbin-fastapi-decorator[file,jwt,db,casdoor]"

Dependencies

The core package depends on:

PackageVersionPurpose
fastapi≥ 0.115.0Web framework
fastapi-decorators≥ 0.5.0Decorator injection mechanism
casbin≥ 1.36.0Policy enforcement engine