|
1 |
| -SQLAlchemy Adapter for PyCasbin |
2 |
| -==== |
3 |
| - |
4 |
| -[](https://www.travis-ci.org/pycasbin/sqlalchemy-adapter) |
5 |
| -[](https://coveralls.io/github/pycasbin/sqlalchemy-adapter) |
6 |
| -[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
7 |
| -[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
8 |
| -[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
9 |
| -[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
10 |
| -[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
11 |
| - |
12 |
| -SQLAlchemy Adapter is the [SQLAlchemy](https://www.sqlalchemy.org) adapter for [PyCasbin](https://github.com/pycasbin/sqlalchemy-adapter). With this library, Casbin can load policy from SQLAlchemy supported database or save policy to it. |
13 |
| - |
14 |
| -Based on [Officially Supported Databases](http://www.sqlalchemy.org/), The current supported databases are: |
15 |
| - |
16 |
| -- PostgreSQL |
17 |
| -- MySQL |
18 |
| -- SQLite |
19 |
| -- Oracle |
20 |
| -- Microsoft SQL Server |
21 |
| -- Firebird |
22 |
| -- Sybase |
23 |
| - |
24 |
| -## Installation |
25 |
| - |
26 |
| -``` |
27 |
| -pip install casbin_sqlalchemy_adapter |
28 |
| -``` |
29 |
| - |
30 |
| -## Simple Example |
31 |
| - |
32 |
| -```python |
33 |
| -import casbin_sqlalchemy_adapter |
34 |
| -import casbin |
35 |
| - |
36 |
| -adapter = casbin_sqlalchemy_adapter.Adapter('sqlite:///test.db') |
37 |
| - |
38 |
| -e = casbin.Enforcer('path/to/model.conf', adapter, True) |
39 |
| - |
40 |
| -sub = "alice" # the user that wants to access a resource. |
41 |
| -obj = "data1" # the resource that is going to be accessed. |
42 |
| -act = "read" # the operation that the user performs on the resource. |
43 |
| - |
44 |
| -if e.enforce(sub, obj, act): |
45 |
| - # permit alice to read data1casbin_sqlalchemy_adapter |
46 |
| - pass |
47 |
| -else: |
48 |
| - # deny the request, show an error |
49 |
| - pass |
50 |
| -``` |
51 |
| - |
52 |
| - |
53 |
| -### Getting Help |
54 |
| - |
55 |
| -- [PyCasbin](https://github.com/casbin/pycasbin) |
56 |
| - |
57 |
| -### License |
58 |
| - |
59 |
| -This project is licensed under the [Apache 2.0 license](LICENSE). |
| 1 | +SQLAlchemy Adapter for PyCasbin |
| 2 | +==== |
| 3 | + |
| 4 | +[](https://www.travis-ci.org/pycasbin/sqlalchemy-adapter) |
| 5 | +[](https://coveralls.io/github/pycasbin/sqlalchemy-adapter) |
| 6 | +[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
| 7 | +[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
| 8 | +[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
| 9 | +[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
| 10 | +[](https://pypi.org/project/casbin_sqlalchemy_adapter/) |
| 11 | + |
| 12 | +SQLAlchemy 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. |
| 13 | + |
| 14 | +Based on [Officially Supported Databases](http://www.sqlalchemy.org/), The current supported databases are: |
| 15 | + |
| 16 | +- PostgreSQL |
| 17 | +- MySQL |
| 18 | +- SQLite |
| 19 | +- Oracle |
| 20 | +- Microsoft SQL Server |
| 21 | +- Firebird |
| 22 | +- Sybase |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +``` |
| 27 | +pip install casbin_sqlalchemy_adapter |
| 28 | +``` |
| 29 | + |
| 30 | +## Simple Example |
| 31 | + |
| 32 | +```python |
| 33 | +import casbin_sqlalchemy_adapter |
| 34 | +import casbin |
| 35 | + |
| 36 | +adapter = casbin_sqlalchemy_adapter.Adapter('sqlite:///test.db') |
| 37 | + |
| 38 | +e = casbin.Enforcer('path/to/model.conf', adapter, True) |
| 39 | + |
| 40 | +sub = "alice" # the user that wants to access a resource. |
| 41 | +obj = "data1" # the resource that is going to be accessed. |
| 42 | +act = "read" # the operation that the user performs on the resource. |
| 43 | + |
| 44 | +if e.enforce(sub, obj, act): |
| 45 | + # permit alice to read data1casbin_sqlalchemy_adapter |
| 46 | + pass |
| 47 | +else: |
| 48 | + # deny the request, show an error |
| 49 | + pass |
| 50 | +``` |
| 51 | + |
| 52 | + |
| 53 | +### Getting Help |
| 54 | + |
| 55 | +- [PyCasbin](https://github.com/casbin/pycasbin) |
| 56 | + |
| 57 | +### License |
| 58 | + |
| 59 | +This project is licensed under the [Apache 2.0 license](LICENSE). |
0 commit comments