{"id":50132369,"url":"https://github.com/apache/casbin-python-sqlalchemy-adapter","last_synced_at":"2026-07-23T12:01:05.291Z","repository":{"id":364128494,"uuid":"878922594","full_name":"apache/casbin-python-sqlalchemy-adapter","owner":"apache","description":"SQLAlchemy Adapter for PyCasbin","archived":false,"fork":false,"pushed_at":"2026-05-15T19:18:36.000Z","size":91,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-07-22T19:27:48.008Z","etag":null,"topics":["abac","acl","adapter","auth","authz","casbin","orm","pycasbin","python","rbac","sql","sqlalchemy"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/pycasbin","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-10-26T13:34:52.000Z","updated_at":"2026-07-22T03:11:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/apache/casbin-python-sqlalchemy-adapter","commit_stats":null,"previous_names":["apache/casbin-python-sqlalchemy-adapter"],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/apache/casbin-python-sqlalchemy-adapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcasbin-python-sqlalchemy-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcasbin-python-sqlalchemy-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcasbin-python-sqlalchemy-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcasbin-python-sqlalchemy-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/casbin-python-sqlalchemy-adapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcasbin-python-sqlalchemy-adapter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35801472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-23T02:00:06.683Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abac","acl","adapter","auth","authz","casbin","orm","pycasbin","python","rbac","sql","sqlalchemy"],"created_at":"2026-05-23T21:00:29.576Z","updated_at":"2026-07-23T12:01:05.283Z","avatar_url":"https://github.com/apache.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"SQLAlchemy Adapter for PyCasbin \r\n====\r\n\r\n[![build](https://github.com/officialpycasbin/sqlalchemy-adapter/actions/workflows/build.yml/badge.svg)](https://github.com/officialpycasbin/sqlalchemy-adapter/actions/workflows/build.yml)\r\n[![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/sqlalchemy-adapter/badge.svg)](https://coveralls.io/github/officialpycasbin/sqlalchemy-adapter)\r\n[![Version](https://img.shields.io/pypi/v/sqlalchemy-adapter.svg)](https://pypi.org/project/sqlalchemy-adapter/)\r\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/sqlalchemy-adapter.svg)](https://pypi.org/project/sqlalchemy-adapter/)\r\n[![Pyversions](https://img.shields.io/pypi/pyversions/sqlalchemy-adapter.svg)](https://pypi.org/project/sqlalchemy-adapter/)\r\n[![Download](https://static.pepy.tech/badge/sqlalchemy-adapter)](https://pypi.org/project/sqlalchemy-adapter/)\r\n[![License](https://img.shields.io/pypi/l/sqlalchemy-adapter.svg)](https://pypi.org/project/sqlalchemy-adapter/)\r\n\r\nSQLAlchemy Adapter is the [SQLAlchemy](https://www.sqlalchemy.org) adapter for [PyCasbin](https://github.com/casbin/pycasbin). With this library, Casbin can load policy from SQLAlchemy supported database or save policy to it.\r\n\r\nBased on [Officially Supported Databases](http://www.sqlalchemy.org/), The current supported databases are:\r\n\r\n- PostgreSQL\r\n- MySQL\r\n- SQLite\r\n- Oracle\r\n- Microsoft SQL Server\r\n- Firebird\r\n- Sybase\r\n\r\n## Installation\r\n\r\n```\r\npip install sqlalchemy_adapter\r\n```\r\n\r\n## Simple Example\r\n\r\nYou can save and load policy to database.\r\n\r\n```python\r\nimport sqlalchemy_adapter\r\nimport casbin\r\n\r\nadapter = sqlalchemy_adapter.Adapter('sqlite:///test.db')\r\n\r\ne = casbin.Enforcer('path/to/model.conf', adapter)\r\n\r\nsub = \"alice\"  # the user that wants to access a resource.\r\nobj = \"data1\"  # the resource that is going to be accessed.\r\nact = \"read\"  # the operation that the user performs on the resource.\r\n\r\nif e.enforce(sub, obj, act):\r\n    # permit alice to read data1\r\n    pass\r\nelse:\r\n    # deny the request, show an error\r\n    pass\r\n```\r\n\r\nBy default, policies are stored in the `casbin_rule` table.\r\nYou can custom the table where the policy is stored by using the `table_name` parameter.\r\n\r\n```python\r\n\r\nimport sqlalchemy_adapter\r\nimport casbin\r\n\r\ncustom_table_name = \"\u003ccustom_table_name\u003e\"\r\n\r\n# create adapter with custom table name.\r\nadapter = sqlalchemy_adapter.Adapter('sqlite:///test.db', table_name=custom_table_name)\r\n\r\ne = casbin.Enforcer('path/to/model.conf', adapter)\r\n```\r\n\r\n## Prevent Automatic Table Creation\r\n\r\nBy default, the adapter automatically creates the necessary database tables during initialization. If you want to use the adapter only as an intermediary without automatically creating tables, you can set the `create_table` parameter to `False`:\r\n\r\n```python\r\nimport sqlalchemy_adapter\r\nimport casbin\r\n\r\n# Create adapter without automatically creating tables\r\nadapter = sqlalchemy_adapter.Adapter('sqlite:///test.db', create_table=False)\r\n\r\ne = casbin.Enforcer('path/to/model.conf', adapter)\r\n```\r\n\r\nThis is useful when:\r\n- Tables are already created by your database migration system\r\n- You want to manage table creation separately\r\n- You are using the adapter as an intermediary between SQLAlchemy and your system\r\n\r\n**Note:** When `create_table=False`, you are responsible for ensuring the required tables exist in the database before using the adapter.\r\n\r\n\r\n### Getting Help\r\n\r\n- [PyCasbin](https://github.com/casbin/pycasbin)\r\n\r\n### License\r\n\r\nThis project is licensed under the [Apache 2.0 license](LICENSE).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcasbin-python-sqlalchemy-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fcasbin-python-sqlalchemy-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcasbin-python-sqlalchemy-adapter/lists"}