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.

Download files

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

Source Distribution

casbin_fastapi_decorator_file-1.2.3.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

casbin_fastapi_decorator_file-1.2.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file casbin_fastapi_decorator_file-1.2.3.tar.gz.

File metadata

  • Download URL: casbin_fastapi_decorator_file-1.2.3.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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}

File hashes

Hashes for casbin_fastapi_decorator_file-1.2.3.tar.gz
Algorithm Hash digest
SHA256 33e7481999683ca90ea6c73466f2788655998d6041e942d757d7b1439a962a71
MD5 7a4cdcd567cbab4e53aea215d29cf0e0
BLAKE2b-256 b269b5fa235148d2bdcbdd1068a48bf66d780ddb3c79099394e0a6f755c0cef1

See more details on using hashes here.

File details

Details for the file casbin_fastapi_decorator_file-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: casbin_fastapi_decorator_file-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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}

File hashes

Hashes for casbin_fastapi_decorator_file-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0cc3afaade310f2e058cbb3e8d043d0967cc7b8ff2b3536a59d17d1208c6f40f
MD5 7eb4efebd3dbb4e16c7d26204c5a8eab
BLAKE2b-256 23869da40317a4d941f1cde4b120bc643081068ff6a85a7441294a91d3035fa5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page