跳转到主要内容

PyCasbin的Redis适配器

项目描述

PyCasbin的Redis适配器

GitHub Action Coverage Status Version PyPI - Wheel Pyversions Download Discord

Redis适配器是redisPyCasbin适配器。使用此库,Casbin可以从redis中加载策略或将策略保存到redis中。

安装

pip install casbin_redis_adapter

简单示例

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

配置

Adapter() 默认启用 decode_responses 并支持任何Redis参数配置。

要使用 casbin_redis_adapter,您必须提供以下参数配置

  • host:redis服务的地址
  • port:redis服务端口

以下参数默认提供

  • db:redis数据库,默认为0
  • username:redis用户名,默认为None
  • password:redis密码,默认为None
  • key:存储casbin规则的key,默认为casbin_rules

有关更多参数,请参考redis-py

获取帮助

许可证

此项目采用Apache 2.0许可证

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

casbin_redis_adapter-1.2.0.tar.gz (9.1 kB 查看哈希值)

上传时间 源代码

构建分发

casbin_redis_adapter-1.2.0-py3-none-any.whl (9.8 kB 查看哈希值)

上传时间 Python 3

支持者