Skip to main content

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.

Metadata

Release files for casbin-async-django-orm-adapter 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for casbin-async-django-orm-adapter 1.1.0
File Size Uploaded Provenance Actions
casbin_async_django_orm_adapter-1.1.0.tar.gz 371.0 kB Without provenance Details for casbin_async_django_orm_adapter-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for casbin-async-django-orm-adapter 1.1.0
File Interpreter ABI Platform Actions
casbin_async_django_orm_adapter-1.1.0-py3-none-any.whl Python 3 none any Details for casbin_async_django_orm_adapter-1.1.0-py3-none-any.whl

Total release size: 777.2 kB

Release files / casbin_async_django_orm_adapter-1.1.0.tar.gz

Download URL casbin_async_django_orm_adapter-1.1.0.tar.gz
Size 371.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1dca0e3635d95770a7816c0563504b52cb1ef3c0d535b952b7dde0421de23dbe
BLAKE2b-256 checksum
How to use checksums
a6ec2b892e277b435cd0898197a7f578100ca1733fe0151fd5966ff2f7824b35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / casbin_async_django_orm_adapter-1.1.0-py3-none-any.whl

Download URL casbin_async_django_orm_adapter-1.1.0-py3-none-any.whl
Size 406.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
819c366e236a7def78561159e4bb4c4b361cd32606acc00a61d7321c41b1e03a
BLAKE2b-256 checksum
How to use checksums
295d13cd174bb08e81101b28d4cffc3c509cff873133bc0db814c3008d3a302b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Security for casbin-async-django-orm-adapter 1.1.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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page