异步Thrift服务器和客户端
项目描述
基于 thriftpy2 的 thrift 协议的 asyncio 实现。
文档: https://aiothrift.readthedocs.org/
安装
$ pip install aiothrift
使用示例
Thrift 文件
service PingPong { string ping(), i64 add(1:i32 a, 2:i64 b), }
服务器
import asyncio
import aiothrift
pingpong_thrift = aiothrift.load('pingpong.thrift', module_name='pingpong_thrift')
class Dispatcher:
def ping(self):
return "pong"
async def add(self, a, b):
await asyncio.sleep(1)
return a + b
async def main():
server = await aiothrift.create_server(pingpong_thrift.PingPong, Dispatcher()))
async with server:
await server.serve_forever()
asyncio.run(main())
客户端
import asyncio
import aiothrift
pingpong_thrift = aiothrift.load('pingpong.thrift', module_name='pingpong_thrift')
async def go():
conn = await aiothrift.create_connection(pingpong_thrift.PingPong)
print(await conn.ping())
print(await conn.add(5, 6))
conn.close()
asyncio.run(go())
或使用 ConnectionPool
import asyncio
import aiothrift
pingpong_thrift = aiothrift.load('pingpong.thrift', module_name='pingpong_thrift')
async def go():
client = await aiothrift.create_pool(pingpong_thrift.PingPong)
print(await client.ping())
print(await client.add(5, 6))
client.close()
await client.wait_closed()
asyncio.run(go())
开始使用 aiothrift 就这么简单,您不必在服务器和客户端双方都使用 aiothrift。所以,如果您已经有一个正常的 thrift 服务器设置,可以自由地创建一个异步 thrift 客户端来与该服务器通信。
需求
Python >= 3.7.0
LICENSE
aiothrift 基于 MIT 许可协议提供。
项目详情
下载文件
下载您平台对应的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
aiothrift-0.2.7.tar.gz (12.6 kB 查看哈希值)
构建分布
aiothrift-0.2.7-py3-none-any.whl (14.0 kB 查看哈希值)
关闭
aiothrift-0.2.7.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cf1485695aabd206f7cd62eb6472734599955244370e8a560a353fe4f50c8d26 |
|
MD5 | 15e40575df54a7f59e2f220935405e51 |
|
BLAKE2b-256 | cb5387777444e5b94f688c64a6374b29679254f403ee859962305b10f7c3b56e |
关闭
aiothrift-0.2.7-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c239ac54a0a3413df7487c17878c13477fcdc4080f11d24774411c193ce7917c |
|
MD5 | 0bf770079915babd8b85d0a02cbb1e52 |
|
BLAKE2b-256 | 9215519131b4c067e331689f8bf7ea4452208191c8730460c41fe9c943b824e5 |