Registry / database / casbin-async-sqlalchemy-adapter

casbin-async-sqlalchemy-adapter

JSON →
library1.17.0pypypi✓ verified 85d ago

Asynchronous SQLAlchemy adapter for PyCasbin, enabling policy storage in relational databases with async support. Current version 1.17.0, requires Python >=3.7. Released regularly alongside PyCasbin releases.

pip install casbin-async-sqlalchemy-adapter
INSTALL
IMPORT
SIG · CASBIN-ASYNC-SQLAL
C
casbin-async-sqlalchemy-adapter
databasepythonv1.17.0
Install
3.7s avg
Import
1014ms
Disk
46MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.17.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.080s · 47MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.7s · import 0.948s · 45MB
46MB installed
● package 46MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Adapter
from casbin_async_sqlalchemy_adapter import Adapter
from casbin_async_sqlalchemy_adapter.adapter import Adapter
Old import path (submodule) no longer works; use top-level import.

Basic usage with sqlite+aiosqlite. Ensure you have aiosqlite installed. The adapter must be initialized with create_table() before use.

import asyncio from casbin import Enforcer from casbin_async_sqlalchemy_adapter import Adapter async def main(): adapter = Adapter('sqlite+aiosqlite:///test.db') # Initialize adapter (creates table) await adapter.create_table() e = Enforcer('path/to/model.conf', adapter) # ... use enforcer await e.enforce('alice', 'data1', 'read') asyncio.run(main())
Debug
Known issues
breakingAdapter import path changed from submodule to top-level.
fix
Use 'from casbin_async_sqlalchemy_adapter import Adapter' instead of 'from casbin_async_sqlalchemy_adapter.adapter import Adapter'.
affects: >=1.0.0
gotchaAdapter does not auto-create table; must call create_table() explicitly.
fix
Call await adapter.create_table() once before using the enforcer.
affects: all
gotchaRequires an async SQLAlchemy driver (e.g., aiosqlite for SQLite, asyncpg for PostgreSQL). Sync drivers will fail.
fix
Use a compatible async driver URL (e.g., 'postgresql+asyncpg://...').
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'casbin_async_sqlalchemy_adapter'
Library not installed or installed without async SQLAlchemy driver.
fix
pip install casbin-async-sqlalchemy-adapter aiosqlite
AttributeError: 'Adapter' object has no attribute 'create_table'
Using an outdated version or incorrect import path.
fix
Import Adapter from top-level and ensure version >=1.0.0.
sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'sqlite:///test.db'
Using sync SQLAlchemy URL without async driver prefix.
fix
Use 'sqlite+aiosqlite:///test.db' for async SQLite.
Upgrade
Version history
1.17.0latest on PyPI · released Dec 10, 2025
Audit
Dependencies
casbinrequiredCore library; adapter is useless without it.
sqlalchemyrequiredORM used for database operations.
asynciorequiredAsync runtime support.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
casbin-async-sqlalchemy-adapter — pip install casbin-async-sqlalchemy-adapter · libregistry