casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Python
What it is and what it does
Casbin is an access control library that enforces authorization decisions based on pluggable models (ACL, RBAC, ABAC, RESTful) and policy rules. It evaluates requests in the form of subject-object-action tuples against a configuration-driven policy engine, returning allow or deny decisions. The library does not handle authentication or user management—it assumes those are handled elsewhere—but it manages role hierarchies, policy storage, and rule matching with built-in operators.
You define your access control model in a CONF file using the PERM metamodel (Policy, Effect, Request, Matchers), then load policies from a CSV file or database. For each access attempt, you call enforce() with the relevant parameters, and Casbin evaluates the request against your policies and returns a boolean. It supports both allow and deny rules, role inheritance, domain/tenant isolation, and attribute-based matching.
Use it for:
- Enforce role-based permissions in a web application where users have different roles (admin, editor, viewer) with different resource access levels.
- Implement fine-grained ACL for a REST API, controlling which users can perform which HTTP methods on which resource paths.
- Add attribute-based access control to a multi-tenant SaaS platform, where access decisions depend on resource ownership or other dynamic attributes.
- Manage hierarchical role structures in an enterprise system where roles inherit permissions from parent roles.
- Centralize authorization logic for microservices by using Casbin as a shared policy engine across multiple services.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Casbin enforces access control policies (ACL, RBAC, ABAC) by evaluating requests against a configurable model and policy rules, returning allow or deny decisions.
Yes. Casbin is actively maintained, has no known vulnerabilities, installs with minimal friction, and is widely adopted (top 5000 on PyPI). It solves a real problem—decoupling authorization logic from application code—and supports multiple access control models. Install it if you need flexible, model-driven authorization; skip it if your access control is trivial or if you prefer inline permission checks.
Install
casbin on PyPI
pip
pip install casbinuv
uv add casbinpoetry
poetry add casbinInstalling casbin
Before you install
Low install friction with a single runtime dependency (simpleeval). Active maintenance with recent releases; last commit 2026-08-13 and 1759 repository stars indicate ongoing development.
License in practice
Apache 2.0 is permissive, allowing commercial and private use with minimal restrictions—suitable for most projects.
Quickstart
pip install casbin
import casbin
e = casbin.Enforcer("model.conf", "policy.csv")
if e.enforce("alice", "data1", "read"):
# access permitted
pass
Requires a model configuration file (CONF format) and a policy file (CSV format) to define access control rules.
Verify before relying
- Whether async support (mentioned as available since 1.23.0) is production-ready and fully documented.
- Performance characteristics and scalability limits for large policy sets.
- Integration patterns with common Python web frameworks beyond the mentioned Django Authorization.
Package facts
| License | Apache 2.0 (permissive) |
| Python support | supports the current Python release (>=3.3) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — simpleeval |
| Maintenance | actively maintained — 461 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,843,231/month — #2,865 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: casbin-1.43.0-py3-none-any.whl
Keywords: casbin, acl, rbac, abac, auth, authz, authorization, access control, permission
Tags
More Security packages
Provides Python bindings to the FreeDesktop.org…
permissive · top 1,000 on PyPI
msalMSAL for Python handles OAuth2 and OpenID…
permissive · top 1,000 on PyPI
joserfcjoserfc implements JOSE standards (JWS, JWE,…
permissive · top 1,000 on PyPI
AuthlibAuthlib provides a complete implementation of…
permissive · top 1,000 on PyPI
argon2-cffi-bindingsProvides low-level CFFI bindings to the…
permissive · top 1,000 on PyPI
adalADAL for Python authenticates applications with…
permissive · top 1,000 on PyPI
pycasbinPyCasbin enforces access control policies using…
permissive · top 5,000 on PyPI
casbin-sqlalchemy-adapterConnects PyCasbin access control policies to…
permissive · top 15,000 on PyPI
casbin-async-sqlalchemy-adapterProvides an asynchronous SQLAlchemy adapter for…
permissive · top 15,000 on PyPI
sqlalchemy-adapterBridges PyCasbin access-control policies with…
permissive · top 5,000 on PyPI
cedarpycedarpy binds the Cedar Policy authorization…
unclear · top 15,000 on PyPI
authAn HTTP authorization service that answers…
permissive · top 15,000 on PyPI
oslo.policyoslo.policy enforces role-based access control…
permissive · top 15,000 on PyPI
invenio-records-permissionsDefines and enforces permission policies for…
permissive · top 15,000 on PyPI
oso-cloudOso Cloud client provides a Python wrapper for…
permissive · top 15,000 on PyPI
winaclParses and manipulates Windows security…
permissive · top 15,000 on PyPI