Tortoise ORM Adapter for PyCasbin
This is an asynchronous adapter for pycasbin using Tortoise ORM.
Supports Python 3.7+.
Installation
python3 -m pip install --user casbin-tortoise-adapter
# or via your favorite dependency manager, like PDM
The current supported databases are limited by Tortoise ORM.
Documentation
The only configurable is the underlying Model used by TortoiseAdapter. While simple, it should be plenty to cover most use cases that one could come across. You can change the model by passing the modelclass: CasbinRule keyword argument to the adapter and updating the model in your Tortoise ORM init configuration.
The modelclass value must inherit from casbin_tortoise_adapter.CasbinRule to ensure that all the expected fields are present. A TypeError will throw if this is not the case.
A custom Model, combined with advanced configuration like show in the Tortoise ORM "Two Databases" example, allow you to change where your authorization rules are stored (database, model name, etc.)
Basic example
from casbin import AsyncEnforcer
from tortoise import Tortoise
from casbin_tortoise_adapter import CasbinRule, TortoiseAdapter
async def main()
# connect to db and generate schemas
await Tortoise.init(
db_url="postgres://postgres:password@test-db:5432/my_app",
modules={"models": ["casbin_tortoise_adapter"]},
)
await Tortoise.generate_schemas()
adapter = casbin_tortoise_adapter.TortoiseAdapter()
e = AsyncEnforcer('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
License
This project, like other adapters, is licensed under the Apache 2.0 License.
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to my forest you’ll be creating employment for local families and restoring wildlife habitats.
Metadata
Release files for casbin-tortoise-adapter 2.0.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_tortoise_adapter-2.0.0.tar.gz | 11.7 kB | Without provenance | Details for casbin_tortoise_adapter-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| casbin_tortoise_adapter-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for casbin_tortoise_adapter-2.0.0-py3-none-any.whl |
Total release size: 21.8 kB
Release files / casbin_tortoise_adapter-2.0.0.tar.gz
| Download URL | casbin_tortoise_adapter-2.0.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d20e8d7a4f3e9c377a76fc611a92da4a06015215372e9b798d6ff3a45cf0755
|
|
BLAKE2b-256 checksum How to use checksums |
0f816f865c18fdf01f8f0daa44fa42309f8c2416a35f969f9fe872654e780f4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.11.1 CPython/3.11.2
|
Release files / casbin_tortoise_adapter-2.0.0-py3-none-any.whl
| Download URL | casbin_tortoise_adapter-2.0.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9bfa71498d672ddc6cdb99e52818bedaf10740c93ab7d66198d677c81c696c3f
|
|
BLAKE2b-256 checksum How to use checksums |
c792e6bfcbe7eaeb26ad0832596f926f7579f4eb0f186b9a49650095157578ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.11.1 CPython/3.11.2
|
Security for casbin-tortoise-adapter 2.0.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.