Skip to main content

casbin-fastapi-decorator-file

File-based enforcer provider with hot-reload for casbin-fastapi-decorator.

Provides CachedFileEnforcerProvider — loads the casbin Enforcer once from model.conf + policy.csv and automatically reloads when either file changes on disk (via watchdog).

Install

pip install casbin-fastapi-decorator-file

Usage

from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException
from casbin_fastapi_decorator import PermissionGuard
from casbin_fastapi_decorator_file import CachedFileEnforcerProvider

provider = CachedFileEnforcerProvider(
    model_path="casbin/model.conf",
    policy_path="casbin/policy.csv",
)

@asynccontextmanager
async def lifespan(app: FastAPI):
    async with provider:   # starts file watcher
        yield              # stops file watcher on shutdown

guard = PermissionGuard(
    user_provider=get_current_user,
    enforcer_provider=provider,
    error_factory=lambda *_: HTTPException(403, "Forbidden"),
)

app = FastAPI(lifespan=lifespan)

@app.get("/articles")
@guard.require_permission("articles", "read")
async def list_articles(): ...

Any change to model.conf or policy.csv is detected automatically — the enforcer reloads on the next request with zero downtime.

Metadata

Release files for casbin-fastapi-decorator-file 1.3.1

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

Source distribution (sdist)

Source distribution for casbin-fastapi-decorator-file 1.3.1
File Size Uploaded
casbin_fastapi_decorator_file-1.3.1.tar.gz 2.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for casbin-fastapi-decorator-file 1.3.1
File Interpreter ABI Platform
casbin_fastapi_decorator_file-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 kB

Release files / casbin_fastapi_decorator_file-1.3.1.tar.gz

Download URL casbin_fastapi_decorator_file-1.3.1.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4d1eda8d0a49f0160b098c33ca9338c6e126a69ced018bd93f2d84fcdd510d55
BLAKE2b-256 checksum
How to use checksums
6972251d4e7a7300701ec0462c5d637d5723065c86f4e0947c26258dd8f5905c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / casbin_fastapi_decorator_file-1.3.1-py3-none-any.whl

Download URL casbin_fastapi_decorator_file-1.3.1-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
226ba761abb546086ba864a5dd51fa809ed67084bd48cadb79c1b262302f3c8c
BLAKE2b-256 checksum
How to use checksums
d84641542d8eadbd2cd3b28b9d59230448edc7d821c11d6594e699c3a87d7ea8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files

1.3.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release 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