async thrift server and client
Project description
aiothrift
======================
Asyncio implementation for thrift protocol, which is heavily based on `thriftpy <https://thriftpy.readthedocs.org/en/latest/>`_.
This project is still in early develop state and thus is not recommended for production usage.
Installation
------------
::
$ pip install aiothrift
Usage example
-------------
Thrift file
^^^^^^^^^^^
::
service PingPong {
string ping(),
i64 add(1:i32 a, 2:i64 b),
}
Client
^^^^^^
.. code:: python
import asyncio
import thriftpy
from aiothrift.server import make_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(
make_server(pingpong_thrift.PingPong, Dispatcher(), '127.0.0.1', 6000, loop=loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
Server
^^^^^^
.. 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, ('127.0.0.1', 6000), loop=loop, timeout=2)
print(await conn.ping())
print(await conn.add(5, 6))
conn.close()
loop.run_until_complete(go())
loop.close()
It's just that simple to begin with ``aiothrift``, and you are not forced to use ``asyncthrift`` 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_
LICENSE
-------
``aiothrift`` is offered under the MIT license.
======================
Asyncio implementation for thrift protocol, which is heavily based on `thriftpy <https://thriftpy.readthedocs.org/en/latest/>`_.
This project is still in early develop state and thus is not recommended for production usage.
Installation
------------
::
$ pip install aiothrift
Usage example
-------------
Thrift file
^^^^^^^^^^^
::
service PingPong {
string ping(),
i64 add(1:i32 a, 2:i64 b),
}
Client
^^^^^^
.. code:: python
import asyncio
import thriftpy
from aiothrift.server import make_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(
make_server(pingpong_thrift.PingPong, Dispatcher(), '127.0.0.1', 6000, loop=loop))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
Server
^^^^^^
.. 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, ('127.0.0.1', 6000), loop=loop, timeout=2)
print(await conn.ping())
print(await conn.add(5, 6))
conn.close()
loop.run_until_complete(go())
loop.close()
It's just that simple to begin with ``aiothrift``, and you are not forced to use ``asyncthrift`` 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_
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.0.2.tar.gz
(8.1 kB
view details)
File details
Details for the file aiothrift-0.0.2.tar.gz
.
File metadata
- Download URL: aiothrift-0.0.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aa7143b997f95e95bcf48f473f1c7f7cc9a3691e63c79612c47bbc40827ea5b |
|
MD5 | e9ffa7b259c61961ff5ccc07d90d2611 |
|
BLAKE2b-256 | de4d2aa199076185e2a999535873effa01f3ff3119729a3dee7ec87f01ce53b5 |