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 details)
Built Distribution
File details
Details for the file aiobsonrpc-0.0.4.tar.gz
.
File metadata
- Download URL: aiobsonrpc-0.0.4.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e592ff652f5c421ff22ee24773432635d429c2af96026c2002c95525e7bdfc6a |
|
MD5 | 8b9382e95762d90952ae8108d7ea83a0 |
|
BLAKE2b-256 | f3e464a4890f5c18d125260357306a7fb6b939ea70f13e8e249ab4db9ec95ff3 |
File details
Details for the file aiobsonrpc-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: aiobsonrpc-0.0.4-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4c2a0051151f82aee11c9d7b6fc25fd926d1387942a4c803b3534f397f6cdae |
|
MD5 | 4e64b1eaeaddc00589db01a4a8574cde |
|
BLAKE2b-256 | 3f6adbfe6dd4b1c487db7460c81b241c6e2c84489c0ca4dc30b24d71534bec29 |