casbin-async-redis-adapter


Namecasbin-async-redis-adapter JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/pycasbin/async-redis-adapter
SummaryAsync Redis Adapter for PyCasbin
upload_time2024-04-06 02:45:23
maintainerNone
docs_urlNone
authorBustDot
requires_python>=3.8
licenseApache 2.0
keywords casbin redis casbin-adapter async rbac access control abac acl permission
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Async Redis Adapter for PyCasbin
====

[![GitHub Actions](https://github.com/pycasbin/async-redis-adapter/workflows/build/badge.svg?branch=master)](https://github.com/pycasbin/async-redis-adapter/actions)
[![Coverage Status](https://coveralls.io/repos/github/pycasbin/async-redis-adapter/badge.svg?branch=master)](https://coveralls.io/github/pycasbin/async-redis-adapter?branch=master)
[![Version](https://img.shields.io/pypi/v/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)
[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)
[![Pyversions](https://img.shields.io/pypi/pyversions/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)
[![Download](https://img.shields.io/pypi/dm/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)
[![License](https://img.shields.io/pypi/l/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)

Async Redis Adapter is the async [redis](https://redis.io/) adapter for [PyCasbin](https://github.com/casbin/pycasbin).
With this
library, Casbin can load policy from redis or save policy to it.

## Installation

```
pip install casbin_async_redis_adapter
```

## Simple Example

```python
import asyncio
from casbin_async_redis_adapter import Adapter
import casbin


async def get_enforcer():
    adapter = Adapter("localhost", 6379, encoding="utf-8")
    e = casbin.AsyncEnforcer("rbac_model.conf", adapter)
    model = e.get_model()

    model.clear_policy()
    model.add_policy("p", "p", ["alice", "data1", "read"])
    await adapter.save_policy(model)

    model.clear_policy()
    model.add_policy("p", "p", ["bob", "data2", "write"])
    await adapter.save_policy(model)

    model.clear_policy()
    model.add_policy("p", "p", ["data2_admin", "data2", "read"])
    await adapter.save_policy(model)

    model.clear_policy()
    model.add_policy("p", "p", ["data2_admin", "data2", "write"])
    await adapter.save_policy(model)

    model.clear_policy()
    model.add_policy("g", "g", ["alice", "data2_admin"])
    await adapter.save_policy(model)

    e = casbin.AsyncEnforcer("rbac_model.conf", adapter)
    await e.load_policy()

    return e


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.


async def main():
    e = await get_enforcer()
    if e.enforce("alice", "data1", "read"):
        print("alice can read data1")
    else:
        print("alice can not read data1")


asyncio.run(main())
```

## Configuration

`Adapter()` enable decode_responses by default and supports any Redis parameter configuration.

To use casbin_redis_adapter, you must provide the following parameter configuration

- `host`: address of the redis service
- `port`: redis service port

The following parameters are provided by default

- `db`: redis database, default is `0`
- `username`: redis username, default is `None`
- `password`: redis password, default is `None`
- `key`: casbin rule to store key, default is `casbin_rules`

For more parameters, please follow [redis-py](https://redis.readthedocs.io/en/stable/connections.html#redis.Redis)

### 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": "https://github.com/pycasbin/async-redis-adapter",
    "name": "casbin-async-redis-adapter",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "casbin, Redis, casbin-adapter, async, rbac, access control, abac, acl, permission",
    "author": "BustDot",
    "author_email": "Bust.dev@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/b8/0c/3f00f0c40835c49a2e13204dc2f8913208e3236700e75ce5b6ea2f6b62fd/casbin_async_redis_adapter-1.2.0.tar.gz",
    "platform": null,
    "description": "Async Redis Adapter for PyCasbin\n====\n\n[![GitHub Actions](https://github.com/pycasbin/async-redis-adapter/workflows/build/badge.svg?branch=master)](https://github.com/pycasbin/async-redis-adapter/actions)\n[![Coverage Status](https://coveralls.io/repos/github/pycasbin/async-redis-adapter/badge.svg?branch=master)](https://coveralls.io/github/pycasbin/async-redis-adapter?branch=master)\n[![Version](https://img.shields.io/pypi/v/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)\n[![PyPI - Wheel](https://img.shields.io/pypi/wheel/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)\n[![Pyversions](https://img.shields.io/pypi/pyversions/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)\n[![Download](https://img.shields.io/pypi/dm/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)\n[![License](https://img.shields.io/pypi/l/casbin_async_redis_adapter.svg)](https://pypi.org/project/casbin_async_redis_adapter/)\n\nAsync Redis Adapter is the async [redis](https://redis.io/) adapter for [PyCasbin](https://github.com/casbin/pycasbin).\nWith this\nlibrary, Casbin can load policy from redis or save policy to it.\n\n## Installation\n\n```\npip install casbin_async_redis_adapter\n```\n\n## Simple Example\n\n```python\nimport asyncio\nfrom casbin_async_redis_adapter import Adapter\nimport casbin\n\n\nasync def get_enforcer():\n    adapter = Adapter(\"localhost\", 6379, encoding=\"utf-8\")\n    e = casbin.AsyncEnforcer(\"rbac_model.conf\", adapter)\n    model = e.get_model()\n\n    model.clear_policy()\n    model.add_policy(\"p\", \"p\", [\"alice\", \"data1\", \"read\"])\n    await adapter.save_policy(model)\n\n    model.clear_policy()\n    model.add_policy(\"p\", \"p\", [\"bob\", \"data2\", \"write\"])\n    await adapter.save_policy(model)\n\n    model.clear_policy()\n    model.add_policy(\"p\", \"p\", [\"data2_admin\", \"data2\", \"read\"])\n    await adapter.save_policy(model)\n\n    model.clear_policy()\n    model.add_policy(\"p\", \"p\", [\"data2_admin\", \"data2\", \"write\"])\n    await adapter.save_policy(model)\n\n    model.clear_policy()\n    model.add_policy(\"g\", \"g\", [\"alice\", \"data2_admin\"])\n    await adapter.save_policy(model)\n\n    e = casbin.AsyncEnforcer(\"rbac_model.conf\", adapter)\n    await e.load_policy()\n\n    return e\n\n\nsub = \"alice\"  # the user that wants to access a resource.\nobj = \"data1\"  # the resource that is going to be accessed.\nact = \"read\"  # the operation that the user performs on the resource.\n\n\nasync def main():\n    e = await get_enforcer()\n    if e.enforce(\"alice\", \"data1\", \"read\"):\n        print(\"alice can read data1\")\n    else:\n        print(\"alice can not read data1\")\n\n\nasyncio.run(main())\n```\n\n## Configuration\n\n`Adapter()` enable decode_responses by default and supports any Redis parameter configuration.\n\nTo use casbin_redis_adapter, you must provide the following parameter configuration\n\n- `host`: address of the redis service\n- `port`: redis service port\n\nThe following parameters are provided by default\n\n- `db`: redis database, default is `0`\n- `username`: redis username, default is `None`\n- `password`: redis password, default is `None`\n- `key`: casbin rule to store key, default is `casbin_rules`\n\nFor more parameters, please follow [redis-py](https://redis.readthedocs.io/en/stable/connections.html#redis.Redis)\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": "Async Redis Adapter for PyCasbin",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/pycasbin/async-redis-adapter"
    },
    "split_keywords": [
        "casbin",
        " redis",
        " casbin-adapter",
        " async",
        " rbac",
        " access control",
        " abac",
        " acl",
        " permission"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "269377386dde0dfef8f14c68ef42f0efbb321fad9b0568667e96c4b0ca130d47",
                "md5": "c6f3bb8de847d3ef02836caa6afc80f9",
                "sha256": "9e08b6b3ae6fcd9463507cd23c188b169cb18e645fb98e6594a1ba6838b97700"
            },
            "downloads": -1,
            "filename": "casbin_async_redis_adapter-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c6f3bb8de847d3ef02836caa6afc80f9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11038,
            "upload_time": "2024-04-06T02:45:22",
            "upload_time_iso_8601": "2024-04-06T02:45:22.422598Z",
            "url": "https://files.pythonhosted.org/packages/26/93/77386dde0dfef8f14c68ef42f0efbb321fad9b0568667e96c4b0ca130d47/casbin_async_redis_adapter-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b80c3f00f0c40835c49a2e13204dc2f8913208e3236700e75ce5b6ea2f6b62fd",
                "md5": "d3e9097e2cec53bedd5a1e67ffa43b93",
                "sha256": "45a1b419b3e5d98b34b3f8166836e4db96759576606a17e3f52877b6eaad66c9"
            },
            "downloads": -1,
            "filename": "casbin_async_redis_adapter-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d3e9097e2cec53bedd5a1e67ffa43b93",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10106,
            "upload_time": "2024-04-06T02:45:23",
            "upload_time_iso_8601": "2024-04-06T02:45:23.950406Z",
            "url": "https://files.pythonhosted.org/packages/b8/0c/3f00f0c40835c49a2e13204dc2f8913208e3236700e75ce5b6ea2f6b62fd/casbin_async_redis_adapter-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-06 02:45:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pycasbin",
    "github_project": "async-redis-adapter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "casbin-async-redis-adapter"
}
        
Elapsed time: 0.21016s