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.2.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.2.0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: varco_casbin-3.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 2b54cddcff263b51793d650d38bf069fd5fd5a64e2e9d771d32ea42604b08619
MD5 835652aa0ede96d3893be80187ffc68e
BLAKE2b-256 272402d0647822c743e5100616e23db158e247108606bbd9fe7080c53c12cecf

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_casbin-3.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: varco_casbin-3.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68c91c4fd448d206980d36701b22d20f587b07d20fff6bc7450fac2dd0114778
MD5 05d2de3e437f1292d5371757b0a7fdeb
BLAKE2b-256 a6f469d74d4cc5a5ae6affa0c93c14b056562238f9deaf9ea925aa9894d5a54e

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_casbin-3.2.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

This release

3.2.0 This release

2 files

3.1.0

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