Skip to content

Commit 1c17ab4

Browse files
Copilotnomeguy
andcommitted
Initial exploration of SQLAlchemy version conflict
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
1 parent f4d9125 commit 1c17ab4

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Metadata-Version: 2.1
2+
Name: casbin-databases-adapter
3+
Version: 1.5.0
4+
Summary: This is an Adapter for PyCasbin that implemented using Databases connection to achieve async process
5+
Home-page: https://github.com/officialpycasbin/casbin-databases-adapter
6+
Author: Isa Setiawan Abdurrazaq
7+
Author-email: isasetiawan@protonmail.com
8+
License: Apache 2.0
9+
Keywords: casbin,asynccasbin,async,databases,casbin-adapter,rbac,access control,abac,acl,permission
10+
Classifier: Programming Language :: Python :: 3.9
11+
Classifier: Programming Language :: Python :: 3.10
12+
Classifier: Programming Language :: Python :: 3.11
13+
Classifier: Programming Language :: Python :: 3.12
14+
Classifier: License :: OSI Approved :: Apache Software License
15+
Classifier: Operating System :: OS Independent
16+
Requires-Python: >=3.3
17+
Description-Content-Type: text/markdown
18+
License-File: LICENSE
19+
20+
# Databases Casbin Adapter
21+
22+
[![build](https://github.com/officialpycasbin/casbin-databases-adapter/actions/workflows/build.yml/badge.svg)](https://github.com/officialpycasbin/casbin-databases-adapter/actions/workflows/build.yml)
23+
[![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/casbin-databases-adapter/badge.svg?branch=master)](https://coveralls.io/github/officialpycasbin/casbin-databases-adapter?branch=master)
24+
[![Version](https://img.shields.io/pypi/v/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
25+
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
26+
[![Pyversions](https://img.shields.io/pypi/pyversions/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
27+
[![Download](https://static.pepy.tech/badge/casbin_databases_adapter)](https://pypi.org/project/casbin_databases_adapter/)
28+
[![License](https://img.shields.io/pypi/l/casbin_databases_adapter.svg)](https://pypi.org/project/casbin_databases_adapter/)
29+
30+
This is an Adapter for [PyCasbin](https://github.com/casbin/pycasbin) that implemented using [Databases](https://www.encode.io/databases) connection to achieve async process
31+
32+
## Installation
33+
34+
```
35+
pip install casbin_databases_adapter
36+
```
37+
38+
## Simple Example
39+
40+
```python
41+
import casbin_databases_adapter
42+
import casbin
43+
from databases import Database
44+
import sqlalchemy
45+
from sqlalchemy import Table, Column, String, Integer
46+
from sqlalchemy.sql.ddl import CreateTable
47+
import asyncio
48+
49+
DATABASE_URL = "sqlite+aiosqlite:///example.db"
50+
51+
async def create_casbin_rule_table(db: Database):
52+
metadata = sqlalchemy.MetaData()
53+
table = Table(
54+
"casbin_rules",
55+
metadata,
56+
Column("id", Integer, primary_key=True),
57+
Column("ptype", String(255)),
58+
Column("v0", String(255)),
59+
Column("v1", String(255)),
60+
Column("v2", String(255)),
61+
Column("v3", String(255)),
62+
Column("v4", String(255)),
63+
Column("v5", String(255)),
64+
)
65+
q = CreateTable(table)
66+
await db.execute(query=str(q))
67+
return table
68+
69+
async def main():
70+
database = Database(DATABASE_URL)
71+
await database.connect()
72+
casbin_rule_table = await create_casbin_rule_table(database)
73+
adapter = casbin_databases_adapter.DatabasesAdapter(db=database, table=casbin_rule_table)
74+
75+
e = casbin.Enforcer('path/to/model.conf', adapter)
76+
77+
sub = "alice" # the user that wants to access a resource.
78+
obj = "data1" # the resource that is going to be accessed.
79+
act = "read" # the operation that the user performs on the resource.
80+
81+
if e.enforce(sub, obj, act):
82+
# permit alice to read data1
83+
pass
84+
else:
85+
# deny the request, show an error
86+
pass
87+
88+
# run the main function
89+
asyncio.run(main())
90+
```
91+
92+
### Getting Help
93+
94+
- [PyCasbin](https://github.com/casbin/pycasbin)
95+
96+
### License
97+
98+
This project is licensed under the [Apache 2.0 license](LICENSE).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LICENSE
2+
README.md
3+
setup.cfg
4+
setup.py
5+
casbin_databases_adapter/__init__.py
6+
casbin_databases_adapter/adapter.py
7+
casbin_databases_adapter.egg-info/PKG-INFO
8+
casbin_databases_adapter.egg-info/SOURCES.txt
9+
casbin_databases_adapter.egg-info/dependency_links.txt
10+
casbin_databases_adapter.egg-info/requires.txt
11+
casbin_databases_adapter.egg-info/top_level.txt
12+
tests/test_adapter.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SQLAlchemy==1.4.42
2+
asynccasbin==1.1.7
3+
databases==0.7.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
casbin_databases_adapter

0 commit comments

Comments
 (0)