具有aether python功能的python库
aether.python的Python项目详细描述
以太Python库
这是带有aether函数的正式python库。
目录
要求
此库需要python 3.6及更高版本。
python库:
- eha-jsonpath 为jsonpath_ng python库提供新的扩展,以提供通常请求的函数
- jsonschema python的json模式验证的实现
- redis 用于redis密钥值存储的python客户端
- requests 人类的http。
- spavro 一个avro库,spavro是一个(sp)eedier avro实现,使用cython
额外依赖项(基于设置):
- 测试
- coverage 一种测量python程序代码覆盖率的工具。
- fakeredis 用于测试目的的redis api的伪实现。
- flake8 执行样式指南的工具。
- flake8-quotes flake8扩展,用于检查python中的引号。
- tblib 回溯序列化库。
安装
# standalone
pip3 install aether.python
分布
如何创建软件包分发版
执行以下命令:
python3 setup.py bdist_wheel
或
./scripts/build.sh
测试
如何测试库
首次安装依赖项(仅执行一次):
./scripts/install.sh
之后执行以下命令:
source ./venv/bin/activate
./scripts/test.sh
文件scripts/test.ini
包含测试中使用的环境变量。
用法
redis工具
它通过提供的redis参数提供到redis服务器的接口。
它提供了许多CRUD
redis操作,包括但不限于:
-在缓存到redis之前,将文档键格式化为_{type}:{tenant}:{id}
。
-基于预成形键检索文档。
-基于预成形键移除文档。
-使用回调函数订阅基于密钥的通道。
用法
from aether.python.redis.task import TaskHelper
REDIS_TASK = TaskHelper(settings, redis_instance)
# Settings must have the following properties:
# REDIS_HOST str - Redis server host,
# REDIS_PORT int - Redis server port,
# REDIS_PASSWORD str - Redis server password,
# REDIS_DB str - Redis database name
# redis_instance (Optional) - Pass an existing redis connection
# (If provided, ignores all settings and uses redis_instance)
document = {
'id': 'document_id',
'name': 'document name'
}
document_type = 'test_document'
aether_tenant = 'prod'
# add document to redis
REDIS_TASK.add(task=document, type=document_type, tenant=aether_tenant)
# retrieve document from redis
REDIS_TASK.get(_id=document['id'], type=document_type, tenant=aether_tenant)
# subcribe to a key based channel
CHANNEL = '_test_document*' # listens for messages published to all channels starting with '_test_document'
def handle_callback(msg):
print(msg) # handle returned message
REDIS_TASK.subscribe(callback=handle_callback, pattern=CHANNEL, keep_alive=True)
# publish document
REDIS_TASK.publish(task=document, type=document_type, tenant=aether_tenant) # this will trigger the 'handle_callback' function with the published document to all subscribed clients