--- id: sqlalchemy-adapter version: "1.9.0" license: Apache 2.0 license_treatment: permissive maintenance: active --- # sqlalchemy-adapter — SQLAlchemy Adapter for PyCasbin License: permissive · Maintenance: active · Downloads: 1.8M/mo ## 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 above — 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 pip install sqlalchemy-adapter uv add sqlalchemy-adapter poetry add sqlalchemy-adapter ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 1.8M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags casbin sqlalchemy adapter, pycasbin database persistence, rbac policy storage, access control database, casbin policy adapter, sqlalchemy casbin integration, acl enforcement database, access-control, policy-persistence, rbac [View on SkillFed](https://skillfed.io/packages/sqlalchemy-adapter) · [View on PyPI](https://pypi.org/project/sqlalchemy-adapter/)