Skip to main content

Async Thrift server and client

Project description

Asyncio implementation for thrift protocol, which is heavily based on thriftpy2.

https://travis-ci.org/ryanwang520/aiothrift.svg?branch=master

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

LICENSE

aiothrift is offered under the MIT license.

Project details


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.6.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

aiothrift-0.2.6-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file aiothrift-0.2.6.tar.gz.

File metadata

  • Download URL: aiothrift-0.2.6.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Darwin/21.2.0

File hashes

Hashes for aiothrift-0.2.6.tar.gz
Algorithm Hash digest
SHA256 da8978e94d9e9bdcefcdfcf8aeb38907211bdb683ad90e3ad53648e87efd1f3d
MD5 48937df0be781c9ba9c9f250c1a76910
BLAKE2b-256 a9ebe42584a3c46ecb56c0f2e924c2b719a0f75f1d82f8daffb720d806cd4bbf

See more details on using hashes here.

File details

Details for the file aiothrift-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: aiothrift-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Darwin/21.2.0

File hashes

Hashes for aiothrift-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 81a5f9b6902763c7ce3ebe9d9c9a08c3edbfc50551115a9efd037f1f31189c95
MD5 3a08a61edd40454a5fe411ff0a27ca27
BLAKE2b-256 ed9e2c8b69342a6f4b0639306b2943d376c3d79bb367be99e76eae219f050f5c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page