Giter Site home page Giter Site logo

aiorpc's Introduction

aiorpc

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

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/.

aiorpc's People

Contributors

choleraehyq avatar dmig avatar volfco avatar pyneda avatar abitfan avatar kathiresan-jayabalan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.