sqlalchemy-adapter
SQLAlchemy Adapter for PyCasbin
What it is and what it does
This package acts as a bridge between pycasbin (a policy enforcement library) and any database that SQLAlchemy supports. Instead of storing access-control policies in memory or flat files, you point it at a database connection string, and it handles loading and saving policy rules to a database table. The adapter automatically creates the necessary schema on first use (unless you disable it), and works transparently with pycasbin's Enforcer to persist role-based access control (RBAC), attribute-based access control (ABAC), and access control list (ACL) policies.
Typical usage involves creating an Adapter with a database URL, passing it to a pycasbin Enforcer along with a policy model file, and then using the Enforcer to check permissions. The adapter manages the database interaction; you focus on policy rules and enforcement logic. It supports custom table names and can be configured to skip automatic table creation if your schema is managed separately.
Use it for:
- Store and load RBAC policies for a multi-tenant application across application restarts.
- Manage ACL rules in a centralized database so multiple service instances enforce the same permissions.
- Persist dynamic policy changes made at runtime without redeploying or restarting the application.
- Migrate access-control policies between different database backends using SQLAlchemy's dialect abstraction.
- Integrate pycasbin policy enforcement into an existing application that already uses SQLAlchemy for data access.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Bridges PyCasbin access-control policies with SQLAlchemy-supported databases, enabling policy persistence and retrieval across PostgreSQL, MySQL, SQLite, Oracle, SQL Server, Firebird, and Sybase.
Yes, if you need to persist pycasbin policies in a relational database. The package is actively maintained, has no known vulnerabilities, and low install friction. It is a straightforward adapter with a narrow, well-defined scope—use it when pycasbin and SQLAlchemy are your architecture; do not install it if you are not already using pycasbin.
Install
sqlalchemy-adapter on PyPI
pip
pip install sqlalchemy-adapteruv
uv add sqlalchemy-adapterpoetry
poetry add sqlalchemy-adapterInstalling sqlalchemy-adapter
Before you install
Low install friction; pure Python wheel with two runtime dependencies (pycasbin and SQLAlchemy). Actively maintained with recent commits and no known vulnerabilities.
License in practice
Apache 2.0 permissive license allows commercial and private use with minimal restrictions; attribution required but no copyleft obligations.
Quickstart
pip install sqlalchemy-adapter
import sqlalchemy_adapter
adapter = sqlalchemy_adapter.Adapter('sqlite:///test.db')
# Pass adapter to pycasbin Enforcer with model config file
# Then use Enforcer to check permissions
Requires a pycasbin model configuration file and an existing or creatable database at the connection string URL.
Verify before relying
- Whether the adapter supports all SQLAlchemy dialects equally or has known limitations with specific databases.
- Performance characteristics and scalability limits when handling large policy rule sets.
- Backward compatibility guarantees across major version updates.
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 — pycasbin, SQLAlchemy |
| Maintenance | actively maintained — 270 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,782,012/month — #3,567 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sqlalchemy_adapter-1.9.0-py3-none-any.whl
Keywords: pycasbin, 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
casbin-sqlalchemy-adapterConnects PyCasbin access control policies to…
permissive · top 15,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
cerbos-sqlalchemyConverts Cerbos authorization query plans into…
permissive · top 15,000 on PyPI
fastapi-users-db-sqlalchemyProvides a SQLAlchemy ORM adapter for FastAPI…
permissive · top 5,000 on PyPI
sqlalchemy-firebirdProvides a SQLAlchemy 2.0+ dialect for…
permissive · top 15,000 on PyPI
sqlalchemy-jdbcapiSQLAlchemy dialect for JDBC and ODBC database…
permissive · top 15,000 on PyPI
sqlalchemy-ibmiProvides a SQLAlchemy dialect to connect to Db2…
permissive · top 15,000 on PyPI
databasesProvides async database access for PostgreSQL,…
permissive · top 5,000 on PyPI