Skip to main content

A fast RPC library based on asyncio and MessagePack

Project description

Copyright (C) 2016 Cholerae hu <choleraehyq@gmail.com>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
Description: aiorpc
======

.. image:: https://badge.fury.io/py/aiorpc.png
:target: http://badge.fury.io/py/aiorpc

.. image:: https://travis-ci.org/choleraehyq/aiorpc.png?branch=master
:target: https://travis-ci.org/choleraehyq/aiorpc

aiorpc is a lightweight asynchronous RPC library. It enables you to easily build a distributed server-side system by writing a small amount of code. It is built on top of `asyncio <https://docs.python.org/3/library/asyncio.html/>`_ and `MessagePack <http://msgpack.org/>`_.


Installation
------------

To install aiorpc, simply:

.. code-block:: bash

$ pip install aiorpc

Examples
--------

RPC server
^^^^^^^^^^

.. code-block:: python

from aiorpc import register, serve

import asyncio
import uvloop


def echo(msg):
return msg

loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)
register("echo", echo)
coro = asyncio.start_server(serve, '127.0.0.1', 6000, loop=loop)
server = loop.run_until_complete(coro)

try:
loop.run_forever()
except KeyboardInterrupt:
server.close()
loop.run_until_complete(server.wait_closed())

RPC client
^^^^^^^^^^

.. code-block:: python

from aiorpc import RPCClient

import asyncio
import uvloop

async def do(cli):
ret = await client.call('echo', 'message')
print("{}\n".format(ret))

loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)
client = RPCClient('127.0.0.1', 6000)
loop.run_until_complete(do(client))
client.close()

Performance
-----------

aiorpc with `uvloop <https://github.com/MagicStack/uvloop>`_ significantly outperforms `ZeroRPC <http://zerorpc.dotcloud.com/>`_ (**6x** faster), which is built using `ZeroMQ <http://zeromq.org/>`_ and `MessagePack <http://msgpack.org/>`_ and slightly underperforms `official MessagePack RPC <https://github.com/msgpack-rpc/msgpack-rpc-python>`_ (**0.7x** slower), which is built using `Facebook's Tornado <http://www.tornadoweb.org/en/stable/>`_ and `MessagePack <http://msgpack.org/>`_.

- aiorpc


.. code-block:: bash

% python benchmarks/benchmark_aiorpc.py
call: 2236 qps


- Official MesssagePack RPC

.. code-block:: bash

% pip install msgpack-rpc-python
% python benchmarks/benchmark_msgpackrpc.py
call: 3112 qps

- ZeroRPC

.. code-block:: bash

% pip install zerorpc
% python benchmarks/benchmark_zerorpc.py
call: 351 qps


Documentation
-------------

Documentation is available at http://aiorpc.readthedocs.org/.
(Since readthedocs don't support Python 3.5 yet, this page is unavailable now.)

Keywords: rpc,msgpack,messagepack,msgpackrpc,messagepackrpc,asyncio
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.5

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aiorpc-0.1.3-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

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