Skip to main content

Async Django ORM adapter for PyCasbin

Project description

async-django-orm-adapter

build Coverage Status Version PyPI - Wheel Pyversions Download Discord

Asynchronous Django ORM Adapter is the async Django 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-async-django-orm-adapter

Add async_casbin_adapter.apps.AsyncCasbinAdapterConfig to your INSTALLED_APPS

# settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

INSTALLED_APPS = [
    ...
    'async_casbin_adapter.apps.AsyncCasbinAdapterConfig',
    ...
]

CASBIN_MODEL = os.path.join(BASE_DIR, 'casbin.conf')

To run schema migration, execute python manage.py migrate async_casbin_adapter

Simple Example

# views.py
from async_casbin_adapter.enforcer import get_enforcer

async 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.

    enforcer = await get_enforcer()
    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. Default to the django adapter shipped with this package: async_casbin_adapter.adapter.AsyncAdapter

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_DB_ALIAS

The database the adapter uses. Default to "default".

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

casbin_async_django_orm_adapter-1.1.0.tar.gz (371.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

casbin_async_django_orm_adapter-1.1.0-py3-none-any.whl (406.2 kB view details)

Uploaded Python 3

File details

Details for the file casbin_async_django_orm_adapter-1.1.0.tar.gz.

File metadata

File hashes

Hashes for casbin_async_django_orm_adapter-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1dca0e3635d95770a7816c0563504b52cb1ef3c0d535b952b7dde0421de23dbe
MD5 fc947c8765fe206e0c2a7a12b2012eb6
BLAKE2b-256 a6ec2b892e277b435cd0898197a7f578100ca1733fe0151fd5966ff2f7824b35

See more details on using hashes here.

File details

Details for the file casbin_async_django_orm_adapter-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for casbin_async_django_orm_adapter-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 819c366e236a7def78561159e4bb4c4b361cd32606acc00a61d7321c41b1e03a
MD5 60364990351e3292d65594fabc369ba6
BLAKE2b-256 295d13cd174bb08e81101b28d4cffc3c509cff873133bc0db814c3008d3a302b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page