{"id":22959845,"url":"https://github.com/pycasbin/sqlalchemy-adapter","last_synced_at":"2025-04-05T19:10:36.731Z","repository":{"id":34246727,"uuid":"165790530","full_name":"pycasbin/sqlalchemy-adapter","owner":"pycasbin","description":"SQLAlchemy Adapter for PyCasbin","archived":false,"fork":false,"pushed_at":"2024-07-08T14:04:12.000Z","size":67,"stargazers_count":75,"open_issues_count":2,"forks_count":37,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T14:40:31.067Z","etag":null,"topics":["abac","access-control","acl","auth","casbin","casbin-adapter","orm","permission","pycasbin","python","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/pycasbin.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}},"created_at":"2019-01-15T05:25:40.000Z","updated_at":"2025-02-18T03:09:56.000Z","dependencies_parsed_at":"2024-05-30T04:52:02.710Z","dependency_job_id":"c6396bef-13b0-4944-b1ca-c3c471c820e4","html_url":"https://github.com/pycasbin/sqlalchemy-adapter","commit_stats":{"total_commits":55,"total_committers":20,"mean_commits":2.75,"dds":0.7636363636363637,"last_synced_commit":"4698e870dcc1ecce9b569eec5d37b99b2fce5cda"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pycasbin%2Fsqlalchemy-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pycasbin%2Fsqlalchemy-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pycasbin%2Fsqlalchemy-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pycasbin%2Fsqlalchemy-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pycasbin","download_url":"https://codeload.github.com/pycasbin/sqlalchemy-adapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386262,"owners_count":20930619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","access-control","acl","auth","casbin","casbin-adapter","orm","permission","pycasbin","python","sqlalchemy"],"created_at":"2024-12-14T18:29:00.423Z","updated_at":"2025-04-05T19:10:36.713Z","avatar_url":"https://github.com/pycasbin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"SQLAlchemy Adapter for PyCasbin \r\n====\r\n\r\n[![GitHub Actions](https://github.com/pycasbin/sqlalchemy-adapter/workflows/build/badge.svg?branch=master)](https://github.com/pycasbin/sqlalchemy-adapter/actions)\r\n[![Coverage Status](https://coveralls.io/repos/github/pycasbin/sqlalchemy-adapter/badge.svg)](https://coveralls.io/github/pycasbin/sqlalchemy-adapter)\r\n[![Version](https://img.shields.io/pypi/v/casbin_sqlalchemy_adapter.svg)](https://pypi.org/project/casbin_sqlalchemy_adapter/)\r\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin_sqlalchemy_adapter.svg)](https://pypi.org/project/casbin_sqlalchemy_adapter/)\r\n[![Pyversions](https://img.shields.io/pypi/pyversions/casbin_sqlalchemy_adapter.svg)](https://pypi.org/project/casbin_sqlalchemy_adapter/)\r\n[![Download](https://img.shields.io/pypi/dm/casbin_sqlalchemy_adapter.svg)](https://pypi.org/project/casbin_sqlalchemy_adapter/)\r\n[![License](https://img.shields.io/pypi/l/casbin_sqlalchemy_adapter.svg)](https://pypi.org/project/casbin_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 casbin_sqlalchemy_adapter\r\n```\r\n\r\n## Simple Example\r\n\r\n```python\r\nimport casbin_sqlalchemy_adapter\r\nimport casbin\r\n\r\nadapter = casbin_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\n## Soft Delete example\r\n\r\nSoft Delete for casbin rules is supported, only when using a custom casbin rule model.\r\nThe Soft Delete mechanism is enabled by passing the attribute of the flag indicating whether\r\na rule is deleted to `db_class_softdelete_attribute`.\r\nThat attribute needs to be of type `sqlalchemy.Boolean`.\r\n\r\n```python\r\nadapter = Adapter(\r\n    engine,\r\n    db_class=MyCustomCasbinRuleModel,\r\n    db_class_softdelete_attribute=MyCustomCasbinRuleModel.is_deleted,\r\n)\r\n```\r\n\r\nPlease be aware that this adapter only sets a flag like `is_deleted` to `True`.\r\nThe provided model needs to handle the update of fields like `deleted_by`, `deleted_at`, etc.\r\nAn example for this is given in [examples/softdelete.py](examples/softdelete.py).\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%2Fpycasbin%2Fsqlalchemy-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpycasbin%2Fsqlalchemy-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpycasbin%2Fsqlalchemy-adapter/lists"}