asyncio MsgPack RPC
Project description
aio-msgpack-rpc
Pure asyncio implementation of the MsgPack RPC.
Uses transports, protocols and streams provided by the asyncio
standard library.
Just a simple implementation of the RPC layer.
Installation
pip install aio-msgpack-rpc
Example
Server
import asyncio
import aio_msgpack_rpc
# handlers can be defined on a class
# they can either be async or plain functions
class MyServicer:
async def sum(self, x, y):
print(f"sum: {x}, {y}")
return x + y
def notification(self, msg):
print(f"notification: {msg}")
async def main():
try:
server = await asyncio.start_server(aio_msgpack_rpc.Server(MyServicer()), host="localhost", port=18002)
while True:
await asyncio.sleep(0.1)
finally:
server.close()
try:
asyncio.get_event_loop().run_until_complete(main())
except KeyboardInterrupt:
pass
Client
import asyncio
import aio_msgpack_rpc
async def main():
client = aio_msgpack_rpc.Client(*await asyncio.open_connection("localhost", 18002))
# blocking rpc calls
result = await client.call("sum", 1, 2)
assert result == 3
# one way notifications
client.notify("notification", "hello")
asyncio.get_event_loop().run_until_complete(main())
Benchmark
Some basic performance benchmarks against the official implementation on my development machine.
package | call (QPS) | notify (QPS) |
---|---|---|
msgpack-rpc-python | 5414 | 11746 |
aio-msgpack-rpc | 5781 | 86957 |
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
aio-msgpack-rpc-0.1.0.tar.gz
(8.2 kB
view hashes)
Built Distribution
Close
Hashes for aio_msgpack_rpc-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ab272f9b4724f953cdacfee4fb8780d246a718963226bbd86072a4913877d79 |
|
MD5 | 5cf15d5e8176e3e66f9843b78719525f |
|
BLAKE2b-256 | 12ca2d200b8de73a54b6c6b9ffa72931bcb1cecace195040adce6429ed60bdda |