skillfed

sqlalchemy-adapter

SQLAlchemy Adapter for PyCasbin

sqlalchemy-adapter v1.9.0 1.8M downloads/30d#3,567 on PyPI7
Permissive license Apache 2.0 Active released

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-adapter

uv

uv add sqlalchemy-adapter

poetry

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 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

License :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.9

Tags

casbin sqlalchemy adapterpycasbin database persistencerbac policy storageaccess control databasecasbin policy adaptersqlalchemy casbin integrationacl enforcement database
access-controlpolicy-persistencerbac

More Database packages

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

redis

Python client library for connecting to and…

permissive · top 1,000 on PyPI

ydb

YDB Python SDK is the official client library…

permissive · top 1,000 on PyPI

snowflake-connector-python

Connects Python applications to Snowflake data…

permissive · top 1,000 on PyPI

sqlparse

sqlparse tokenizes SQL text into a tree of…

permissive · top 1,000 on PyPI

dbt-adapters

Provides base adapter protocols and shared…

permissive · top 1,000 on PyPI

casbin-async-sqlalchemy-adapter

Provides an asynchronous SQLAlchemy adapter for…

permissive · top 15,000 on PyPI

casbin-sqlalchemy-adapter

Connects PyCasbin access control policies to…

permissive · top 15,000 on PyPI

casbin

Casbin enforces access control policies (ACL,…

permissive · top 5,000 on PyPI

pycasbin

PyCasbin enforces access control policies using…

permissive · top 5,000 on PyPI

cerbos-sqlalchemy

Converts Cerbos authorization query plans into…

permissive · top 15,000 on PyPI

fastapi-users-db-sqlalchemy

Provides a SQLAlchemy ORM adapter for FastAPI…

permissive · top 5,000 on PyPI

sqlalchemy-firebird

Provides a SQLAlchemy 2.0+ dialect for…

permissive · top 15,000 on PyPI

sqlalchemy-jdbcapi

SQLAlchemy dialect for JDBC and ODBC database…

permissive · top 15,000 on PyPI

sqlalchemy-ibmi

Provides a SQLAlchemy dialect to connect to Db2…

permissive · top 15,000 on PyPI

databases

Provides async database access for PostgreSQL,…

permissive · top 5,000 on PyPI