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