casbin-tortoise-adapter


Namecasbin-tortoise-adapter JSON
Version 2.0.0 PyPI version JSON
download
home_page
SummaryTortoise ORM adapter for AsyncCasbin
upload_time2023-12-31 16:40:13
maintainer
docs_urlNone
author
requires_python<4.0,>=3.7
licenseApache-2.0
keywords casbin asyncio access control tortoise orm authorization pycasbin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Tortoise ORM Adapter for PyCasbin

![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/thearchitector/casbin-tortoise-adapter/ci.yaml?label=tests&style=flat-square)
![PyPI - Downloads](https://img.shields.io/pypi/dm/casbin-tortoise-adapter?style=flat-square)
![GitHub](https://img.shields.io/github/license/thearchitector/casbin-tortoise-adapter?style=flat-square)
[![Buy a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen?style=flat-square)](https://ecologi.com/eliasgabriel?r=6128126916bfab8bd051026c)

This is an asynchronous adapter for [pycasbin](https://pypi.org/project/casbin) using Tortoise ORM.

Supports Python 3.7+.

## Installation

```sh
python3 -m pip install --user casbin-tortoise-adapter
# or via your favorite dependency manager, like PDM
```

The current supported databases are [limited by Tortoise ORM](https://tortoise.github.io/databases.html).

## Documentation

The only configurable is the underlying Model used by `TortoiseAdapter`. While simple, it should be plenty to cover most use cases that one could come across. You can change the model by passing the `modelclass: CasbinRule` keyword argument to the adapter and updating the model in your Tortoise ORM init configuration.

The `modelclass` value must inherit from `casbin_tortoise_adapter.CasbinRule` to ensure that all the expected fields are present. A `TypeError` will throw if this is not the case.

A custom Model, combined with advanced configuration like show in the Tortoise ORM ["Two Databases" example](https://tortoise.github.io/examples/basic.html#two-databases), allow you to change where your authorization rules are stored (database, model name, etc.)

## Basic example

```python
from casbin import AsyncEnforcer
from tortoise import Tortoise

from casbin_tortoise_adapter import CasbinRule, TortoiseAdapter

async def main()
    # connect to db and generate schemas
    await Tortoise.init(
        db_url="postgres://postgres:password@test-db:5432/my_app",
        modules={"models": ["casbin_tortoise_adapter"]},
    )
    await Tortoise.generate_schemas()

    adapter = casbin_tortoise_adapter.TortoiseAdapter()
    e = AsyncEnforcer('path/to/model.conf', adapter)

    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 data1
        pass
    else:
        # deny the request, show an error
        pass
```

### License

This project, like other adapters, is licensed under the [Apache 2.0 License](LICENSE).

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://ecologi.com/eliasgabriel?r=6128126916bfab8bd051026c) to thank us for our work. By contributing to my forest you’ll be creating employment for local families and restoring wildlife habitats.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "casbin-tortoise-adapter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": "",
    "keywords": "casbin asyncio access control Tortoise ORM authorization pycasbin",
    "author": "",
    "author_email": "Elias Gabriel <me@eliasfgabriel.com>",
    "download_url": "https://files.pythonhosted.org/packages/0f/81/6f865c18fdf01f8f0daa44fa42309f8c2416a35f969f9fe872654e780f4a/casbin_tortoise_adapter-2.0.0.tar.gz",
    "platform": null,
    "description": "# Tortoise ORM Adapter for PyCasbin\n\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/thearchitector/casbin-tortoise-adapter/ci.yaml?label=tests&style=flat-square)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/casbin-tortoise-adapter?style=flat-square)\n![GitHub](https://img.shields.io/github/license/thearchitector/casbin-tortoise-adapter?style=flat-square)\n[![Buy a tree](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-lightgreen?style=flat-square)](https://ecologi.com/eliasgabriel?r=6128126916bfab8bd051026c)\n\nThis is an asynchronous adapter for [pycasbin](https://pypi.org/project/casbin) using Tortoise ORM.\n\nSupports Python 3.7+.\n\n## Installation\n\n```sh\npython3 -m pip install --user casbin-tortoise-adapter\n# or via your favorite dependency manager, like PDM\n```\n\nThe current supported databases are [limited by Tortoise ORM](https://tortoise.github.io/databases.html).\n\n## Documentation\n\nThe only configurable is the underlying Model used by `TortoiseAdapter`. While simple, it should be plenty to cover most use cases that one could come across. You can change the model by passing the `modelclass: CasbinRule` keyword argument to the adapter and updating the model in your Tortoise ORM init configuration.\n\nThe `modelclass` value must inherit from `casbin_tortoise_adapter.CasbinRule` to ensure that all the expected fields are present. A `TypeError` will throw if this is not the case.\n\nA custom Model, combined with advanced configuration like show in the Tortoise ORM [\"Two Databases\" example](https://tortoise.github.io/examples/basic.html#two-databases), allow you to change where your authorization rules are stored (database, model name, etc.)\n\n## Basic example\n\n```python\nfrom casbin import AsyncEnforcer\nfrom tortoise import Tortoise\n\nfrom casbin_tortoise_adapter import CasbinRule, TortoiseAdapter\n\nasync def main()\n    # connect to db and generate schemas\n    await Tortoise.init(\n        db_url=\"postgres://postgres:password@test-db:5432/my_app\",\n        modules={\"models\": [\"casbin_tortoise_adapter\"]},\n    )\n    await Tortoise.generate_schemas()\n\n    adapter = casbin_tortoise_adapter.TortoiseAdapter()\n    e = AsyncEnforcer('path/to/model.conf', adapter)\n\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 data1\n        pass\n    else:\n        # deny the request, show an error\n        pass\n```\n\n### License\n\nThis project, like other adapters, is licensed under the [Apache 2.0 License](LICENSE).\n\nThis package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://ecologi.com/eliasgabriel?r=6128126916bfab8bd051026c) to thank us for our work. By contributing to my forest you\u2019ll be creating employment for local families and restoring wildlife habitats.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Tortoise ORM adapter for AsyncCasbin",
    "version": "2.0.0",
    "project_urls": {
        "Changelog": "https://github.com/thearchitector/casbin-tortoise-adapter/blob/main/CHANGELOG.md",
        "Documentation": "https://github.com/thearchitector/casbin-tortoise-adapter#tortoise-orm-adapter-for-asynccasbin",
        "Repository": "https://github.com/thearchitector/casbin-tortoise-adapter"
    },
    "split_keywords": [
        "casbin",
        "asyncio",
        "access",
        "control",
        "tortoise",
        "orm",
        "authorization",
        "pycasbin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c792e6bfcbe7eaeb26ad0832596f926f7579f4eb0f186b9a49650095157578ed",
                "md5": "66c5cdf7e178b88214670cb9df9a1811",
                "sha256": "9bfa71498d672ddc6cdb99e52818bedaf10740c93ab7d66198d677c81c696c3f"
            },
            "downloads": -1,
            "filename": "casbin_tortoise_adapter-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66c5cdf7e178b88214670cb9df9a1811",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 10096,
            "upload_time": "2023-12-31T16:40:11",
            "upload_time_iso_8601": "2023-12-31T16:40:11.372555Z",
            "url": "https://files.pythonhosted.org/packages/c7/92/e6bfcbe7eaeb26ad0832596f926f7579f4eb0f186b9a49650095157578ed/casbin_tortoise_adapter-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f816f865c18fdf01f8f0daa44fa42309f8c2416a35f969f9fe872654e780f4a",
                "md5": "55fd5c27f264bc0f4e6900995912e148",
                "sha256": "8d20e8d7a4f3e9c377a76fc611a92da4a06015215372e9b798d6ff3a45cf0755"
            },
            "downloads": -1,
            "filename": "casbin_tortoise_adapter-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "55fd5c27f264bc0f4e6900995912e148",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 11691,
            "upload_time": "2023-12-31T16:40:13",
            "upload_time_iso_8601": "2023-12-31T16:40:13.342911Z",
            "url": "https://files.pythonhosted.org/packages/0f/81/6f865c18fdf01f8f0daa44fa42309f8c2416a35f969f9fe872654e780f4a/casbin_tortoise_adapter-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-31 16:40:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thearchitector",
    "github_project": "casbin-tortoise-adapter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "casbin-tortoise-adapter"
}
        
Elapsed time: 0.18076s