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.3.tar.gz
(12.3 kB
view details)
Built Distribution
aiothrift-0.2.3-py3-none-any.whl
(13.7 kB
view details)
File details
Details for the file aiothrift-0.2.3.tar.gz
.
File metadata
- Download URL: aiothrift-0.2.3.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.0 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53ccda1e61e66f7e0d53369f5ef87f5ba722e0a222c9e4e47e8ec90ac4eaa7de |
|
MD5 | 4f8e77830aa28603174ec15a5c1df3ee |
|
BLAKE2b-256 | 8a4d11c3686a2ba1c0e2454bef8286f4f536ffcfc6459353cfa6b370f9f992cd |
File details
Details for the file aiothrift-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: aiothrift-0.2.3-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.0 Darwin/19.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a3801a0dd124ff94932b0c937d276d427af123f3391545395d242b31e6094ef |
|
MD5 | ddbcd975f3d472e9dcac53bb567ed48e |
|
BLAKE2b-256 | 22070b54502623a329e0a4e76715dfa718fdf4619a7aaca01d1cbcc97cfdb8b8 |