casbin-django-orm-adapter


Namecasbin-django-orm-adapter JSON
Version 1.3.0 PyPI version JSON
download
home_pageNone
SummaryDjango's ORM adapter for PyCasbin
upload_time2024-03-29 11:29:15
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 No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Django ORM Adapter for PyCasbin

[![GitHub Action](https://github.com/pycasbin/django-orm-adapter/workflows/build/badge.svg?branch=master)](https://github.com/pycasbin/django-orm-adapter/actions)
[![Coverage Status](https://coveralls.io/repos/github/pycasbin/django-orm-adapter/badge.svg)](https://coveralls.io/github/pycasbin/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/pycasbin/django-orm-adapter). 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/3d/66/e558b6598a4f3680a6d9ccb68a0ea9dce408b570887e852b4593fbe951da/casbin-django-orm-adapter-1.3.0.tar.gz",
    "platform": null,
    "description": "# Django ORM Adapter for PyCasbin\n\n[![GitHub Action](https://github.com/pycasbin/django-orm-adapter/workflows/build/badge.svg?branch=master)](https://github.com/pycasbin/django-orm-adapter/actions)\n[![Coverage Status](https://coveralls.io/repos/github/pycasbin/django-orm-adapter/badge.svg)](https://coveralls.io/github/pycasbin/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/pycasbin/django-orm-adapter). 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.3.0",
    "project_urls": {
        "Home-page": "https://github.com/pycasbin/django-orm-adapter"
    },
    "split_keywords": [
        "casbin",
        " adapter",
        " storage-driver",
        " django",
        " orm",
        " django-orm",
        " access-control",
        " authorization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e414f8dfe24108de072fdbb807f262f558cfc237df675ed58561fc1c8413c939",
                "md5": "f0b25f09662fe167144f16934b3654cc",
                "sha256": "92bb8812c5bf6b47b2646d58b5609dd65ed900a865b5d9331421020cf27ec5dc"
            },
            "downloads": -1,
            "filename": "casbin_django_orm_adapter-1.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f0b25f09662fe167144f16934b3654cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 400790,
            "upload_time": "2024-03-29T11:29:13",
            "upload_time_iso_8601": "2024-03-29T11:29:13.471810Z",
            "url": "https://files.pythonhosted.org/packages/e4/14/f8dfe24108de072fdbb807f262f558cfc237df675ed58561fc1c8413c939/casbin_django_orm_adapter-1.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3d66e558b6598a4f3680a6d9ccb68a0ea9dce408b570887e852b4593fbe951da",
                "md5": "13765366dfe6fe2a26d13132d7f118ca",
                "sha256": "4c45ad3e6ed64f656f76c98db4be124502f1319261eccad73fb5290150aac128"
            },
            "downloads": -1,
            "filename": "casbin-django-orm-adapter-1.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "13765366dfe6fe2a26d13132d7f118ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 367306,
            "upload_time": "2024-03-29T11:29:15",
            "upload_time_iso_8601": "2024-03-29T11:29:15.553776Z",
            "url": "https://files.pythonhosted.org/packages/3d/66/e558b6598a4f3680a6d9ccb68a0ea9dce408b570887e852b4593fbe951da/casbin-django-orm-adapter-1.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 11:29:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pycasbin",
    "github_project": "django-orm-adapter",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "casbin-django-orm-adapter"
}
        
Elapsed time: 0.20925s