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.

Release files for casbin-fastapi-decorator-file 1.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 casbin-fastapi-decorator-file 1.3.0
File Size Uploaded
casbin_fastapi_decorator_file-1.3.0.tar.gz 2.9 kB Details

Built distribution (wheel)

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

Total release size: 6.9 kB

Release files / casbin_fastapi_decorator_file-1.3.0.tar.gz

Download URL casbin_fastapi_decorator_file-1.3.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
56728ba1945eb2738b4e282a0e08ffc3467d9ab2617e576a3f75910afe29c013
BLAKE2b-256 checksum
How to use checksums
6381d92c689bfc79ede595c5b4da111578e456e0dd742f7d88d762d87a48dc82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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.0-py3-none-any.whl

Download URL casbin_fastapi_decorator_file-1.3.0-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e322c4abd5b2f67f9f097ba255769ef9d2e393326b6f1202840f749eb3789e38
BLAKE2b-256 checksum
How to use checksums
c2549de234dea531341ed775a2b20841e37694e84554ceb79e7e0d4f9244fa93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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.0 This release

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