aio-msgpack-rpc
Pure asyncio implementation of the MsgPack RPC.
Requires Python >= 3.6.
Uses streams API 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
await 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 |
Release files for aio-msgpack-rpc 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aio_msgpack_rpc-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / aio_msgpack_rpc-0.2.0-py3-none-any.whl
| Download URL | aio_msgpack_rpc-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ad7e1b632c0e84aef555d59cf2bba6c1140a37779d82d8012abdf03b51341d3
|
|
BLAKE2b-256 checksum How to use checksums |
f82849950dca125b1e5125ac2cc0b0c23ade91b28ebf9f32c41f250abe9e2ea1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|