Skip to main content

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.

Files for aiobsonrpc, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size aiobsonrpc-0.0.4-py3-none-any.whl (12.2 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size aiobsonrpc-0.0.4.tar.gz (8.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page