Async Thrift server and client
Project description
Asyncio implementation for thrift protocol, which is heavily based on thriftpy2.
Documentation: https://aiothrift.readthedocs.org/
Installation
$ pip install aiothrift
Usage example
Thrift file
service PingPong { string ping(), i64 add(1:i32 a, 2:i64 b), }
Server
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())
Client
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())
Or use 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())
It’s just that simple to begin with aiothrift, and you are not forced to use aiothrift on both server and client side. So if you already have a normal thrift server setup, feel free to create an async thrift client to communicate with that server.
Requirements
Python >= 3.7.0
LICENSE
aiothrift is offered under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiothrift-0.2.1.tar.gz
(11.7 kB
view hashes)
Built Distribution
aiothrift-0.2.1-py3-none-any.whl
(13.1 kB
view hashes)
Close
Hashes for aiothrift-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f17a2334cfafab187e075c93b13ae8f716454948c9bcfa051b408563d2566c9b |
|
MD5 | a54c1fd127f1e2736deb6fc21ee2fafe |
|
BLAKE2b-256 | df0b9671f3eab5d3220abcc992e06f9872fd0c1033e1355ea0025e494cb51e98 |