Skip to main content

A fast RPC library based on asyncio and MessagePack

Project description

https://badge.fury.io/py/aiorpc.png https://travis-ci.org/choleraehyq/aiorpc.png?branch=master

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 and MessagePack.

Note aiorpc is under development, should not be considered to have a stable API.

Installation

To install aiorpc, simply:

$ pip install aiorpc

Examples

RPC server

from aiorpc import RPCServer

import asyncio
import uvloop


def echo(msg):
    return msg

rpc_server = RPCServer()
loop = uvloop.new_event_loop()
asyncio.set_event_loop(loop)
rpc_server.register("echo", echo)
coro = asyncio.start_server(rpc_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

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()

aiorpc client can also be used as an async context manager:

async def do():
    async with RPCClient('127.0.0.1', 6000) as client:
        ret = await client.call('echo', 'message')
        print("{}\n".format(ret))

Performance

aiorpc with uvloop significantly outperforms ZeroRPC (6x faster), which is built using ZeroMQ and MessagePack and slightly underperforms official MessagePack RPC (0.7x slower), which is built using Facebook’s Tornado and MessagePack.

  • aiorpc

% python benchmarks/benchmark_aiorpc.py
call: 2236 qps
  • Official MesssagePack RPC

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

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

Documentation

Documentation is available at http://aiorpc.readthedocs.org/.

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

aiorpc-0.1.7.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

aiorpc-0.1.7-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file aiorpc-0.1.7.tar.gz.

File metadata

  • Download URL: aiorpc-0.1.7.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for aiorpc-0.1.7.tar.gz
Algorithm Hash digest
SHA256 875dc5fd5afcbc4799bdfbd30f52bc91df1ea56843be69077cf3320db627c91c
MD5 ea8206d03f85f4997ff3f42ae3dd0eb9
BLAKE2b-256 14ed8e2a771dd083dc7ed6d6a044be0aec8b76405fd94710cafd7d32384b9ed6

See more details on using hashes here.

File details

Details for the file aiorpc-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: aiorpc-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for aiorpc-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1a617f70dbb0be945abf4a97ef3722190278c0b720b5f7f967fbc3c4059be2e4
MD5 35043b2a641b1f43b55b6b7122031fca
BLAKE2b-256 93b2d23950320c76eb22559eed1676b42e7129fb901025eee3b9f8de43e07a33

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