casbin-django-orm-adapter


Namecasbin-django-orm-adapter JSON
Version 1.4.0 PyPI version JSON
download
home_pageNone
SummaryDjango's ORM adapter for PyCasbin
upload_time2024-10-26 13:31:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseApache 2.0
keywords casbin adapter storage-driver django orm django-orm access-control authorization
VCS
bugtrack_url
requirements casbin Django
Travis-CI No Travis.
coveralls test coverage
            # Django ORM Adapter for PyCasbin

[![GitHub Action](https://github.com/officialpycasbin/django-orm-adapter/workflows/build/badge.svg?branch=master)](https://github.com/officialpycasbin/django-orm-adapter/actions)
[![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/django-orm-adapter/badge.svg)](https://coveralls.io/github/officialpycasbin/django-orm-adapter)
[![Version](https://img.shields.io/pypi/v/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)
[![Pyversions](https://img.shields.io/pypi/pyversions/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)
[![Download](https://img.shields.io/pypi/dm/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)

Django ORM Adapter is the [Django](https://www.djangoproject.com/)'s [ORM](https://docs.djangoproject.com/en/3.0/ref/databases/) adapter for [PyCasbin](https://github.com/casbin/pycasbin). With this library, Casbin can load policy from Django ORM supported database or save policy to it.

Based on [Officially Supported Databases](https://docs.djangoproject.com/en/3.0/ref/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`

```python
# 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

```python
# 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

- [PyCasbin](https://github.com/casbin/pycasbin)

### License

This project is licensed under the [Apache 2.0 license](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "casbin-django-orm-adapter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "casbin, adapter, storage-driver, django, orm, django-orm, access-control, authorization",
    "author": null,
    "author_email": "Yang Luo <hsluoyz@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/38/c9/8ac317d358f273ba9d1f62106d0a8d75cbfacca86f4209496a45de5f1134/casbin_django_orm_adapter-1.4.0.tar.gz",
    "platform": null,
    "description": "# Django ORM Adapter for PyCasbin\n\n[![GitHub Action](https://github.com/officialpycasbin/django-orm-adapter/workflows/build/badge.svg?branch=master)](https://github.com/officialpycasbin/django-orm-adapter/actions)\n[![Coverage Status](https://coveralls.io/repos/github/officialpycasbin/django-orm-adapter/badge.svg)](https://coveralls.io/github/officialpycasbin/django-orm-adapter)\n[![Version](https://img.shields.io/pypi/v/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)\n[![Pyversions](https://img.shields.io/pypi/pyversions/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)\n[![Download](https://img.shields.io/pypi/dm/casbin-django-orm-adapter.svg)](https://pypi.org/project/casbin-django-orm-adapter/)\n[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)\n\nDjango ORM Adapter is the [Django](https://www.djangoproject.com/)'s [ORM](https://docs.djangoproject.com/en/3.0/ref/databases/) adapter for [PyCasbin](https://github.com/casbin/pycasbin). With this library, Casbin can load policy from Django ORM supported database or save policy to it.\n\nBased on [Officially Supported Databases](https://docs.djangoproject.com/en/3.0/ref/databases/), The current supported databases are:\n\n- PostgreSQL\n- MariaDB\n- MySQL\n- Oracle\n- SQLite\n- IBM DB2\n- Microsoft SQL Server\n- Firebird\n- ODBC\n\n## Installation\n\n```\npip install casbin-django-orm-adapter\n```\n\nAdd `casbin_adapter.apps.CasbinAdapterConfig` to your `INSTALLED_APPS`\n\n```python\n# settings.py\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))\n\nINSTALLED_APPS = [\n    ...\n    'casbin_adapter.apps.CasbinAdapterConfig',\n    ...\n]\n\nCASBIN_MODEL = os.path.join(BASE_DIR, 'casbin.conf')\n```\n\nTo run schema migration, execute `python manage.py migrate casbin_adapter`\n\n## Simple Example\n\n```python\n# views.py\nfrom casbin_adapter.enforcer import enforcer\n\ndef hello(request):\n    sub = \"alice\"  # the user that wants to access a resource.\n    obj = \"data1\"  # the resource that is going to be accessed.\n    act = \"read\"  # the operation that the user performs on the resource.\n\n    if e.enforce(sub, obj, act):\n        # permit alice to read data1casbin_django_orm_adapter\n        pass\n    else:\n        # deny the request, show an error\n        pass\n```\n\n## Configuration\n\n### `CASBIN_MODEL`\nA string containing the file location of your casbin model.\n\n### `CASBIN_ADAPTER`\nA string containing the adapter import path. Default to the django adapter shipped with this package: `casbin_adapter.adapter.Adapter`\n\n### `CASBIN_ADAPTER_ARGS`\nA tuple of arguments to be passed into the constructor of the adapter specified\nin `CASBIN_ADAPTER`. Refer to adapters to see available arguments. \n\nE.g. if you wish to use the file adapter \nset the adapter to `casbin.persist.adapters.FileAdapter` and use\n`CASBIN_ADAPTER_ARGS = ('path/to/policy_file.csv',)`\n\n### `CASBIN_DB_ALIAS`\nThe database the adapter uses. Default to \"default\".\n\n### `CASBIN_WATCHER`\nWatcher instance to be set as the watcher on the enforcer instance.\n\n### `CASBIN_ROLE_MANAGER`\nRole manager instance to be set as the role manager on the enforcer instance.\n\n\n### Getting Help\n\n- [PyCasbin](https://github.com/casbin/pycasbin)\n\n### License\n\nThis project is licensed under the [Apache 2.0 license](LICENSE).\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Django's ORM adapter for PyCasbin",
    "version": "1.4.0",
    "project_urls": {
        "Home-page": "https://github.com/officialpycasbin/django-orm-adapter"
    },
    "split_keywords": [
        "casbin",
        " adapter",
        " storage-driver",
        " django",
        " orm",
        " django-orm",
        " access-control",
        " authorization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0918dce41e07ad5e5080d451566b61ceb1a7858ddc70e9a4edbf1b52d6c4162d",
                "md5": "89c952edfa5a937d4d50095379b72f54",
                "sha256": "336f0d5460319b53e657f875022456549686405c505e77ce76bf8fdc19516039"
            },
            "downloads": -1,
            "filename": "casbin_django_orm_adapter-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89c952edfa5a937d4d50095379b72f54",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 403965,
            "upload_time": "2024-10-26T13:31:04",
            "upload_time_iso_8601": "2024-10-26T13:31:04.479521Z",
            "url": "https://files.pythonhosted.org/packages/09/18/dce41e07ad5e5080d451566b61ceb1a7858ddc70e9a4edbf1b52d6c4162d/casbin_django_orm_adapter-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38c98ac317d358f273ba9d1f62106d0a8d75cbfacca86f4209496a45de5f1134",
                "md5": "260198af71f3b9784fb2c844339125ca",
                "sha256": "3323f7696c469e52b67cf390297e5e5dbdb076fafe0722ceb8110257907e3214"
            },
            "downloads": -1,
            "filename": "casbin_django_orm_adapter-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "260198af71f3b9784fb2c844339125ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 370101,
            "upload_time": "2024-10-26T13:31:06",
            "upload_time_iso_8601": "2024-10-26T13:31:06.096243Z",
            "url": "https://files.pythonhosted.org/packages/38/c9/8ac317d358f273ba9d1f62106d0a8d75cbfacca86f4209496a45de5f1134/casbin_django_orm_adapter-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-26 13:31:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "officialpycasbin",
    "github_project": "django-orm-adapter",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "casbin",
            "specs": [
                [
                    ">=",
                    "1.16.10"
                ]
            ]
        },
        {
            "name": "Django",
            "specs": []
        }
    ],
    "lcname": "casbin-django-orm-adapter"
}
        
Elapsed time: 0.82517s