Databases Casbin Adapter
This is an Adapter for PyCasbin that implemented using Databases connection to achieve async process
Installation
pip install casbin_databases_adapter
Simple Example
import casbin_databases_adapter
import casbin
from databases import Database
import sqlalchemy
from sqlalchemy import Table, Column, String, Integer
from sqlalchemy.sql.ddl import CreateTable
import asyncio
DATABASE_URL = "sqlite+aiosqlite:///example.db"
async def create_casbin_rule_table(db: Database):
metadata = sqlalchemy.MetaData()
table = Table(
"casbin_rules",
metadata,
Column("id", Integer, primary_key=True),
Column("ptype", String(255)),
Column("v0", String(255)),
Column("v1", String(255)),
Column("v2", String(255)),
Column("v3", String(255)),
Column("v4", String(255)),
Column("v5", String(255)),
)
q = CreateTable(table)
await db.execute(query=str(q))
return table
async def main():
database = Database(DATABASE_URL)
await database.connect()
casbin_rule_table = await create_casbin_rule_table(database)
adapter = casbin_databases_adapter.DatabasesAdapter(db=database, table=casbin_rule_table)
e = casbin.Enforcer('path/to/model.conf', adapter)
sub = "alice" # the user that wants to access a resource.
obj = "data1" # the resource that is going to be accessed.
act = "read" # the operation that the user performs on the resource.
if e.enforce(sub, obj, act):
# permit alice to read data1
pass
else:
# deny the request, show an error
pass
# run the main function
asyncio.run(main())
Getting Help
License
This project is licensed under the Apache 2.0 license.
Metadata
Release files for casbin-databases-adapter 1.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| casbin_databases_adapter-1.6.0.tar.gz | 8.3 kB | Without provenance | Details for casbin_databases_adapter-1.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| casbin_databases_adapter-1.6.0-py3-none-any.whl | Python 3 | none | any | Details for casbin_databases_adapter-1.6.0-py3-none-any.whl |
Total release size: 16.5 kB
Release files / casbin_databases_adapter-1.6.0.tar.gz
| Download URL | casbin_databases_adapter-1.6.0.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1534a9eedcef63fec76b1fe876537a67d5fd99bb311d0a51873d0dc9648ce68c
|
|
BLAKE2b-256 checksum How to use checksums |
98c364a2658069a79801f4f9d64780fb2f93e0e4bf902d487f82099c2253ae55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / casbin_databases_adapter-1.6.0-py3-none-any.whl
| Download URL | casbin_databases_adapter-1.6.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e68add21be28aba94510bc96c9776b38068c011b871353ea967f3316e68bc9f
|
|
BLAKE2b-256 checksum How to use checksums |
c5ef487c0894460598efbeee29c36a478d6512fc0846ec08663260f670a454fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Security for casbin-databases-adapter 1.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.