Django's ORM adapter for PyCasbin
Project description
Django ORM Adapter for PyCasbin
Django ORM Adapter is the Django's ORM adapter for PyCasbin. With this library, Casbin can load policy from Django ORM supported database or save policy to it.
Based on Officially Supported Databases, The current supported databases are:
- PostgreSQL
- MariaDB
- MySQL
- Oracle
- SQLite
- IBM DB2
- Microsoft SQL Server
- Firebird
- ODBC
Installation
pip install casbin-django-orm-adapter
Add casbin_adapter.apps.CasbinAdapterConfig
to your INSTALLED_APPS
# settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
INSTALLED_APPS = [
...
'casbin_adapter.apps.CasbinAdapterConfig',
...
]
CASBIN_MODEL = os.path.join(BASE_DIR, 'casbin.conf')
To run schema migration, execute python manage.py migrate casbin_adapter
Simple Example
# views.py
from casbin_adapter.enforcer import enforcer
def hello(request):
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 data1casbin_django_orm_adapter
pass
else:
# deny the request, show an error
pass
Configuration
CASBIN_MODEL
A string containing the file location of your casbin model.
CASBIN_ADAPTER
A string containing the adapter import path. Defaults to the django adapter shipped with this package: casbin_adapter.adapter.Adapter
CASBIN_ADAPTER_ARGS
A tuple of arguments to be passed into the constructor of the adapter specified
in CASBIN_ADAPTER
. Refer to adapters to see available arguments.
E.g. if you wish to use the file adapter
set the adapter to casbin.persist.adapters.FileAdapter
and use
CASBIN_ADAPTER_ARGS = ('path/to/policy_file.csv',)
CASBIN_WATCHER
Watcher instance to be set as the watcher on the enforcer instance.
CASBIN_ROLE_MANAGER
Role manager instance to be set as the role manager on the enforcer instance.
Getting Help
License
This project is licensed under the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file casbin-django-orm-adapter-1.0.3.tar.gz
.
File metadata
- Download URL: casbin-django-orm-adapter-1.0.3.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52cecaeb2d1bfedb0f1d98d73a508e72a18d1df13750f57bf36dfd7a0a208454 |
|
MD5 | 46017fe279902e4c5a890440273d6903 |
|
BLAKE2b-256 | d9d811297e005e9b10e9c7772884e764cbfe142af100b90ab503d54e3e2b6c07 |
File details
Details for the file casbin_django_orm_adapter-1.0.3-py3-none-any.whl
.
File metadata
- Download URL: casbin_django_orm_adapter-1.0.3-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87c551126b730a86452761d4eb90cb96885f157de760840c1955bbefa5f701a9 |
|
MD5 | 5b1c7e4f06357d543ccdad20a24adf07 |
|
BLAKE2b-256 | 685f30690dd58d95dd7540678b1d5595e3c65ad28799c7e4a15518351dceb7e8 |