casbin-sqlalchemy-adapter
SQLAlchemy Adapter for PyCasbin
What it is and what it does
This package bridges PyCasbin (a flexible access control library) and SQLAlchemy, letting you store and retrieve authorization policies in any database that SQLAlchemy supports. Instead of keeping policies in memory or in a static file, you define your access control model in Casbin's configuration format and let this adapter handle reading and writing rules to your database of choice—PostgreSQL, MySQL, SQLite, Oracle, SQL Server, Firebird, or Sybase.
You instantiate an Adapter with a database connection string, pass it to a Casbin Enforcer along with your model configuration, and then use Casbin's standard enforce() method to check whether a subject (user) can perform an action on an object (resource). The adapter also supports soft-delete semantics if you need to mark rules as deleted without removing them from the database, though you must implement the deletion timestamp logic yourself.
Use it for:
- Store RBAC (role-based access control) rules in PostgreSQL for a multi-tenant SaaS application where policies change frequently.
- Persist ABAC (attribute-based access control) policies in SQLite for a desktop application that needs offline policy evaluation.
- Load access control lists from an existing Oracle database to enforce fine-grained permissions in a legacy system migration.
- Implement soft-delete auditing of permission changes by marking rules as deleted while preserving a historical record.
- Centralize authorization policy management across microservices by storing all rules in a shared MySQL database.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Connects PyCasbin access control policies to SQLAlchemy-supported databases, allowing policies to be loaded from and persisted to PostgreSQL, MySQL, SQLite, Oracle, SQL Server, Firebird, or Sybase.
Yes, if you are already using PyCasbin and need to persist policies in a relational database. The low install friction, permissive license, and broad database support make it a straightforward choice for that use case. However, note that maintenance is dormant (no release in 767 days), so if you encounter bugs or need features, you may need to fork or patch it yourself. No known vulnerabilities as of the query date.
Install
casbin-sqlalchemy-adapter on PyPI
pip
pip install casbin-sqlalchemy-adapteruv
uv add casbin-sqlalchemy-adapterpoetry
poetry add casbin-sqlalchemy-adapterInstalling casbin-sqlalchemy-adapter
Before you install
Low friction install with two runtime dependencies (casbin and SQLAlchemy). Maintenance is dormant—last release was 767 days ago—but the repository remains active with a recent commit on 2024-07-08 and no archived status.
License in practice
Licensed under Apache 2.0 (permissive), so you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install casbin_sqlalchemy_adapter
import casbin_sqlalchemy_adapter
import casbin
adapter = casbin_sqlalchemy_adapter.Adapter('sqlite:///test.db')
e = casbin.Enforcer('path/to/model.conf', adapter)
if e.enforce("alice", "data1", "read"):
# permit alice to read data1
pass
Requires a Casbin model configuration file (model.conf) defining your access control rules and a supported SQLAlchemy database connection string.
Verify before relying
- Whether soft delete functionality works reliably with all supported database backends.
- Performance characteristics when enforcing policies against large rule sets in production.
- Compatibility with recent major versions of SQLAlchemy (1.4+) beyond what classifiers indicate.
Package facts
| License | Apache 2.0 (permissive) |
| Python support | supports the current Python release (>=3.3) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — casbin, SQLAlchemy |
| Maintenance | dormant — 767 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 400,666/month — #6,936 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: casbin_sqlalchemy_adapter-1.4.0-py3-none-any.whl
Keywords: casbin, SQLAlchemy, casbin-adapter, rbac, access control, abac, acl, permission
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,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
casbinCasbin enforces access control policies (ACL,…
permissive · top 5,000 on PyPI
pycasbinPyCasbin enforces access control policies using…
permissive · top 5,000 on PyPI
sqlalchemy-jdbcapiSQLAlchemy dialect for JDBC and ODBC database…
permissive · top 15,000 on PyPI
sqlalchemy-firebirdProvides a SQLAlchemy 2.0+ dialect for…
permissive · top 15,000 on PyPI
cerbos-sqlalchemyConverts Cerbos authorization query plans into…
permissive · top 15,000 on PyPI
django-db-connection-poolProvides connection pooling for Django database…
permissive · top 15,000 on PyPI
databasesProvides async database access for PostgreSQL,…
permissive · top 5,000 on PyPI
fastapi-users-db-sqlalchemyProvides a SQLAlchemy ORM adapter for FastAPI…
permissive · top 5,000 on PyPI