Skip to main content

async thrift server and client

Project description

aiothrift
=========

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

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


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
^^^^^^

.. code:: python

import asyncio
import thriftpy
from aiothrift.server import create_server

pingpong_thrift = thriftpy.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

loop = asyncio.get_event_loop()
server = loop.run_until_complete(
create_server(pingpong_thrift.PingPong, Dispatcher(), loop=loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()

Client
^^^^^^

.. code:: python

import thriftpy
import asyncio
import aiothrift

loop = asyncio.get_event_loop()
pingpong_thrift = thriftpy.load('pingpong.thrift', module_name='pingpong_thrift')

async def go():
conn = await aiothrift.create_connection(pingpong_thrift.PingPong, loop=loop)
print(await conn.ping())
print(await conn.add(5, 6))
conn.close()

loop.run_until_complete(go())
loop.close()

Or use ConnectionPool
^^^^^^^^^^^^^^^^^^^^^

.. code:: python

import thriftpy
import asyncio
import aiothrift

loop = asyncio.get_event_loop()
pingpong_thrift = thriftpy.load('pingpong.thrift', module_name='pingpong_thrift')

async def go():
pool = await aiothrift.create_pool(pingpong_thrift.PingPong, loop=loop)
async with pool.get() as conn:
print(await conn.ping())
print(await conn.add(5, 6))
pool.close()
await pool.wait_closed()

loop.run_until_complete(go())
loop.close()


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.4.2
- async-timeout_
- thriftpy_

.. _async-timeout: https://pypi-hypernode.com/pypi/async_timeout
.. _thriftpy: https://thriftpy.readthedocs.org/en/latest/


LICENSE
-------

``aiothrift`` is offered under the MIT license.


Changelog
=========

Here you can see the full list of changes between each ``aiothrift`` release.

Version 0.1
-----------

First public release.

Version 0.1.1
-----------

allow kyeword arguments to `create_server`


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

Uploaded Source

Built Distribution

aiothrift-0.1.1-py2.py3-none-any.whl (15.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: aiothrift-0.1.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiothrift-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3188481a47e3521f940bcfc67b5f98d41c1ee8e3e733239c38be8e56f98462cd
MD5 bb19cc067b0bedc3933bda4809928a00
BLAKE2b-256 416c28d90506939ef7d5fcde612461ae34a8ff545298bdb599e84b26c8db125e

See more details on using hashes here.

File details

Details for the file aiothrift-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for aiothrift-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6efc31dd8fb6c04e78c23b59100b5702c5bc3703ad7757bf3ced62058564317c
MD5 6df5ff4db9d8f7bf0011eb05d1073ecb
BLAKE2b-256 85584c778bb0fa339010e27c3231cba3480a7baf89753779e52f70a79b9d916d

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