Serf编排工具的Python客户端
项目描述
trio-serf是Serf(一个用于服务发现和编排的去中心化解决方案)的异步Python接口。
它使用trio <https://github.com/python-trio/trio>作为其底层的异步框架。之前的版本使用了anyio <https://github.com/agronholm/anyio>包装器,因此与asyncio、trio和curio兼容,但由于错误处理问题,这一功能已被取消。
安装
trio-serf需要一个正在运行的Serf代理。有关说明,请参阅Serf代理文档。
要安装trio-serf,请运行以下命令
$ pip install trio-serf
或者(尽管如此,您真的应该使用pip)
$ easy_install trio-serf
或者从源码
$ python setup.py install
入门指南
以下示例需要运行异步循环。推荐使用Trio <https://github.com/python-trio/trio>,尽管asyncio也可以使用。
from trio_serf import serf_client
async with serf_client() as client:
await client.event('foo', 'bar')
流使用
from trio_serf import serf_client
async with serf_client() as client:
async with client.stream('*') as stream:
async for resp in stream:
print(resp)
开发
您可以使用以下命令运行测试
$ serf agent --tag foo=bar & # start serf agent
$ python3 -mpytest tests