Skip to main content

Django's ORM adapter for PyCasbin

Project description

Django ORM Adapter for PyCasbin

Build Status Coverage Status Version PyPI - Wheel Pyversions Download License

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_LOG_ENABLED

If True, enables logging. False by default.

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


Download files

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

Source Distribution

casbin-django-orm-adapter-1.0.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file casbin-django-orm-adapter-1.0.1.tar.gz.

File metadata

File hashes

Hashes for casbin-django-orm-adapter-1.0.1.tar.gz
Algorithm Hash digest
SHA256 58992b4e7ec4a2f41e2e5dab09b542c9ccea0cd80123bc0716e8b0753870d599
MD5 3509509f589a718999aa3627e6f4f70a
BLAKE2b-256 62a507388934db10a5ecaf56d1278e24983250aeac95734a6c12031f519ee353

See more details on using hashes here.

File details

Details for the file casbin_django_orm_adapter-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for casbin_django_orm_adapter-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54dd7e02a81e951b3e12cd1a8a19e4eb88ee875a8cb986a5e9852a487d357dce
MD5 fda446dc33f31afcabb57b29ce9bef8b
BLAKE2b-256 5cbf09f613a84e64b87fb98f1a271c8a63d344a3ce6be8931c0af1b31a04e2a1

See more details on using hashes here.

Supported by

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