Skip to main content

varco-casbin

PyPI version Casbin policy-engine authorization backend for varco — ACL, RBAC, and ABAC with dynamic, persisted policies and a ready-made REST management router.

varco_casbin implements the backend-agnostic policy seam defined in varco_core.auth.policy:

varco_core.auth.PolicyEngine        ← enforce(request) hot path
varco_core.auth.PolicyManagement    ← add/remove/list rules + role assignments
        ↑ both implemented by
varco_casbin.CasbinPolicyEngine     ← wraps casbin.AsyncEnforcer
        ↑ bridged into the service layer by
varco_core.auth.PolicyEngineAuthorizer  (opt-in via CasbinAuthorizationConfiguration)
        ↑ administered over REST by
varco_casbin.CasbinPolicyRouter     ← varco_fastapi GenericRouter (requires the [fastapi] extra)

Install

pip install varco-casbin                 # engine only (in-memory / file policies)
pip install "varco-casbin[sqlalchemy]"   # + durable SQL-backed policy store
pip install "varco-casbin[beanie]"       # + durable MongoDB-backed policy store (Beanie)
pip install "varco-casbin[fastapi]"      # + REST management router

Quick start (DI)

from providify import DIContainer
from varco_casbin.di import bootstrap, enable_policy_authorizer
from varco_core.auth import PolicyEngine, PolicyManagement, AbstractAuthorizer

container = bootstrap(DIContainer())  # scans the engine + settings
enable_policy_authorizer(container)  # opt-in: bind the authorizer

engine: PolicyEngine = await container.aget(PolicyEngine)
mgmt: PolicyManagement = await container.aget(PolicyManagement)

await mgmt.add_role_for_user("alice", "admin")  # g, alice, admin
await mgmt.add_policy("admin", "*", "*")  # p, admin, *, *

Configuration

All settings read from VARCO_CASBIN_* env vars (see CasbinSettings):

Env var Default Meaning
VARCO_CASBIN_MODEL_PRESET rbac acl / rbac / rbac_domains / abac
VARCO_CASBIN_MODEL_PATH explicit .conf model file (overrides preset)
VARCO_CASBIN_ADAPTER memory memory / file / sqlalchemy / beanie
VARCO_CASBIN_DB_URL SQLAlchemy URL for sqlalchemy, or Mongo URL for beanie
VARCO_CASBIN_DB_NAME MongoDB database name — required for adapter=beanie
VARCO_CASBIN_POLICY_PATH CSV path for the file adapter
VARCO_CASBIN_ADMIN_ROLE admin role the REST router requires by default

memory is non-durable (dev/test only); file is single-process (concurrent writers can corrupt the CSV); sqlalchemy and beanie both support dynamic, durable, concurrent CRUD — pick whichever matches the rest of your persistence stack.

REST management

Mount build_policy_router(...) (requires [fastapi]) to administer policies and role assignments over REST — all endpoints guarded by require_roles(admin_role):

from varco_casbin.router import build_policy_router

app.include_router(build_policy_router(engine, server_auth=auth))  # engine = CasbinPolicyEngine
GET/POST/DELETE /authz/policies   # p-rules
GET/POST/DELETE /authz/roles      # g-rules (role assignments)
POST            /authz/check      # test an enforcement decision
POST            /authz/reload     # reload from the durable store

See the varco docs (technical_docs/features/casbin-authorization.md) for the full guide, including the ABAC example.

Download files

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

Source Distribution

varco_casbin-3.1.0.tar.gz (61.3 kB view details)

Uploaded Source

Built Distribution

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

varco_casbin-3.1.0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file varco_casbin-3.1.0.tar.gz.

File metadata

  • Download URL: varco_casbin-3.1.0.tar.gz
  • Upload date:
  • Size: 61.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for varco_casbin-3.1.0.tar.gz
Algorithm Hash digest
SHA256 86f2ec98e0c70cba3ddc2bf66c4fc0f9a3e0f4d4ee823b84acc0a667a32f17a7
MD5 81878f09300334d97c589b99b2c95c09
BLAKE2b-256 6f40aa36524ec4246b9acea1358173eb07decd37b55275dae21bb990b29a4653

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_casbin-3.1.0.tar.gz:

Publisher: release.yml on edoardoscarpaci/varco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file varco_casbin-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: varco_casbin-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for varco_casbin-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1ea63e2ced851939d1003adf4475fcb977ed0b6c218c13aa10614ab011af4b9
MD5 a340256a87676480e1753666b4b0ba0b
BLAKE2b-256 71b0e6cf3fad1793273508ef95deebf235b673eb0ecb95f1a40547dac21ea1ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_casbin-3.1.0-py3-none-any.whl:

Publisher: release.yml on edoardoscarpaci/varco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

3.2.0

2 files

This release

3.1.0 This release

2 files

3.0.0

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