cachet api的python 3客户端
cachet-client的Python项目详细描述
缓存客户端
一个python 3.6+api客户端,用于开放源码状态页系统 Cachet。
这个包的目标是创建一个用户友好的界面 到缓存API。
- 资源作为对象返回,这些对象清楚地分隔只读
我们可以改变的属性。原始json响应
始终在
attrs
属性中可用 - 在整个代码库中积极使用类型提示 轻松完成代码
- 在引擎盖下正确分页。方法列出资源 将返回发电机。您可以配置起始页和 适合这种情况的页面大小。每个新页面都指向 一个新的http请求。
- 无论资源类型如何,客户端都在使用单个会话 使更复杂的工作更快(连接重用)
- 一组非常广泛的测试/单元测试。
- 易于扩展和测试
- 文档
安装
pip install cachet-client
示例
importcachetclientfromcachetclient.v1importenumsclient=cachetclient.Client(endpoint='https://status.test/api/v1',api_token='secrettoken',)
检查API是否响应
ifclient.ping():print("Cachet is up and running!")
创建和删除订户
sub=client.subscribers.create(email='user@example.test',verify=True)sub.delete()
列出所有已分页的订阅服务器(生成器)。每一个新页面都会被获取 从引擎盖下的服务器。
forsubinclient.subscribers.list(page=1,per_page=100):print(sub.id,sub.email)
创建组件问题
issue=client.incidents.create(name="Something blew up!",message="We are looking into it",status=enums.INCIDENT_INVESTIGATING,# Optional for component issuescomponent_id=mycomponent.id,component_status=enums.COMPONENT_STATUS_MAJOR_OUTAGE,)
。以及缓存API支持的大多数其他功能
地方发展
本地设置:
python -m virtualenv .venv . .venv/bin/activate pip install -e .
测试
这个项目有一个相当广泛的测试设置。
- 单元测试位于
tests/
中,包括一个伪 缓存API的实现。 - 下面是一个简单的测试脚本 需要缓存的运行测试实例。
运行单元测试
pip install -r tests/requirements.txt tox # Optionally tox -e py36 # tests only tox -e pep8 # for pep8 run only# Running tests wity pytest also works, but this works poorly in combination with enviroment variables for the live test script (tox separates enviroments) pytest tests/
使用真正的缓存服务进行测试
不要在生产系统中再次运行此脚本。 这只是测试服务。 可以使用docker在本地轻松设置缓存:https://github.com/CachetHQ/Docker
您需要设置以下环境变量。
CACHET_ENDPOINT CACHET_API_TOKEN
运行测试:
python extras/live_run.py ... ================================================= Numer of tests : 10 Succesful : 8 Failure : 2 Percentage passed : 80.0% =================================================
构建文档
pip install -r docs/requirements.txt python setup.py build_sphinx
贡献
不要犹豫是否打开问题或提交已完成的 或部分拉取请求。所有贡献者 经验水平是受欢迎的。