Skip to main content

Django ORM Adapter for PyCasbin

build Coverage Status Version PyPI - Wheel Pyversions Download Discord

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. Default 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_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-django-orm-adapter 1.7.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-django-orm-adapter 1.7.0
File Size Uploaded
casbin_django_orm_adapter-1.7.0.tar.gz 370.3 kB Details

Built distribution (wheel)

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

Total release size: 774.7 kB

Release files / casbin_django_orm_adapter-1.7.0.tar.gz

Download URL casbin_django_orm_adapter-1.7.0.tar.gz
Size 370.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8e6b2c451e4c5bdbd4effbd4c320e08cb427a90a5a6ae557ed8ff8dcb7014cc7
BLAKE2b-256 checksum
How to use checksums
04be63b28a288d49a39f36987e5c9f13291e4bcc585c29dee34759fe5da8264e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / casbin_django_orm_adapter-1.7.0-py3-none-any.whl

Download URL casbin_django_orm_adapter-1.7.0-py3-none-any.whl
Size 404.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bd137bc166ddc8d527a5af1b095a15c704f5bad5672c4b5d5693df55c6beb39
BLAKE2b-256 checksum
How to use checksums
4b7d672caac9d849521c79f60c07ce266104a5ecd8738dec9cc769c4f2a95605
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files

1.6.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.1

2 release files

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