Redis Adapter for PyCasbin
====
[](https://github.com/officialpycasbin/redis-adapter/actions/workflows/build.yml)
[](https://coveralls.io/github/officialpycasbin/redis-adapter)
[](https://pypi.org/project/casbin_redis_adapter/)
[](https://pypi.org/project/casbin_redis_adapter/)
[](https://pypi.org/project/casbin_redis_adapter/)
[](https://pypi.org/project/casbin_redis_adapter/)
[](https://discord.gg/S5UjpzGZjN)
Redis Adapter is the [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_redis_adapter
```
## Simple Example
```python
import casbin_redis_adapter
import casbin
adapter = casbin_redis_adapter.Adapter('localhost', 6379)
e = casbin.Enforcer('path/to/model.conf', adapter, True)
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_sqlalchemy_adapter
pass
else:
# deny the request, show an error
pass
```
## 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/officialpycasbin/redis-adapter",
"name": "casbin-redis-adapter",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "casbin, Redis, casbin-adapter, rbac, access control, abac, acl, permission",
"author": "Casbin",
"author_email": "admin@casbin.org",
"download_url": "https://files.pythonhosted.org/packages/ba/6a/bf1b3355338e80f94f1c39028b87608be31eb892a4b838ca3b10073d8c08/casbin_redis_adapter-1.5.0.tar.gz",
"platform": null,
"description": "Redis Adapter for PyCasbin\n====\n\n[](https://github.com/officialpycasbin/redis-adapter/actions/workflows/build.yml)\n[](https://coveralls.io/github/officialpycasbin/redis-adapter)\n[](https://pypi.org/project/casbin_redis_adapter/)\n[](https://pypi.org/project/casbin_redis_adapter/)\n[](https://pypi.org/project/casbin_redis_adapter/)\n[](https://pypi.org/project/casbin_redis_adapter/)\n[](https://discord.gg/S5UjpzGZjN)\n\nRedis Adapter is the [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.\n\n## Installation\n\n```\npip install casbin_redis_adapter\n```\n\n## Simple Example\n\n```python\nimport casbin_redis_adapter\nimport casbin\n\nadapter = casbin_redis_adapter.Adapter('localhost', 6379)\n\ne = casbin.Enforcer('path/to/model.conf', adapter, True)\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\nif e.enforce(sub, obj, act):\n # permit alice to read data1casbin_sqlalchemy_adapter\n pass\nelse:\n # deny the request, show an error\n pass\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": "Redis Adapter for PyCasbin",
"version": "1.5.0",
"project_urls": {
"Homepage": "https://github.com/officialpycasbin/redis-adapter"
},
"split_keywords": [
"casbin",
" redis",
" casbin-adapter",
" rbac",
" access control",
" abac",
" acl",
" permission"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ec85d57c104fbe568695e1a97e486a67235f49e2f8e629445c9949b170761f79",
"md5": "1b99f7d9bcc8ab587adf120f42f6fcd7",
"sha256": "3d769b7392073499ed42fa8135ec11711e82eefef952df8ee070b14817d7316b"
},
"downloads": -1,
"filename": "casbin_redis_adapter-1.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1b99f7d9bcc8ab587adf120f42f6fcd7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9924,
"upload_time": "2025-08-21T01:26:47",
"upload_time_iso_8601": "2025-08-21T01:26:47.708215Z",
"url": "https://files.pythonhosted.org/packages/ec/85/d57c104fbe568695e1a97e486a67235f49e2f8e629445c9949b170761f79/casbin_redis_adapter-1.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "ba6abf1b3355338e80f94f1c39028b87608be31eb892a4b838ca3b10073d8c08",
"md5": "fca512dbd56d9bf797af29c076ec1cb9",
"sha256": "17c7026b8b5460e41787591b4b09cb57193dd10d6cee2ed5883be40d551a7359"
},
"downloads": -1,
"filename": "casbin_redis_adapter-1.5.0.tar.gz",
"has_sig": false,
"md5_digest": "fca512dbd56d9bf797af29c076ec1cb9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9229,
"upload_time": "2025-08-21T01:26:48",
"upload_time_iso_8601": "2025-08-21T01:26:48.471343Z",
"url": "https://files.pythonhosted.org/packages/ba/6a/bf1b3355338e80f94f1c39028b87608be31eb892a4b838ca3b10073d8c08/casbin_redis_adapter-1.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-21 01:26:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "officialpycasbin",
"github_project": "redis-adapter",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pycasbin",
"specs": [
[
">=",
"2.0.0"
]
]
},
{
"name": "redis",
"specs": [
[
">=",
"4.5.0"
]
]
}
],
"lcname": "casbin-redis-adapter"
}