A Python library for JSON-RPC 2.0
Project description
aiobsonrpc
bsonrpc for asyncio.
Python 3.5+
Getting Started
Installing
pip install aiobsonrpc
Example
Server
import asyncio
import aiobsonrpc
@aiobsonrpc.service_class
class EchoService(object):
@aiobsonrpc.aio_rpc_request
async def echo(self, _, data):
await asyncio.sleep(1)
return data
async def on_connected(reader, writer):
aiobsonrpc.JSONRpc(reader, writer, services=EchoService())
if __name__ == '__main__':
loop = asyncio.get_event_loop()
server = asyncio.start_server(on_connected, '0.0.0.0', 6789, loop=loop)
loop.create_task(server)
loop.run_forever()
Client
import asyncio
import aiobsonrpc
async def do_connect():
reader, writer = await asyncio.open_connection('localhost', 6789, loop=loop)
rpc = aiobsonrpc.JSONRpc(reader, writer)
peer = rpc.get_peer_proxy(timeout=5)
result = await peer.echo(123)
print(result) # 123
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(do_connect())
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
aiobsonrpc-0.0.4.tar.gz
(8.3 kB
view hashes)
Built Distribution
aiobsonrpc-0.0.4-py3-none-any.whl
(12.2 kB
view hashes)
Close
Hashes for aiobsonrpc-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4c2a0051151f82aee11c9d7b6fc25fd926d1387942a4c803b3534f397f6cdae |
|
MD5 | 4e64b1eaeaddc00589db01a4a8574cde |
|
BLAKE2b-256 | 3f6adbfe6dd4b1c487db7460c81b241c6e2c84489c0ca4dc30b24d71534bec29 |