Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

fast JSON-RPC protocol implementation for asyncio, without transport

Project description

# aio-jsonrpc-2.0

[![Build Status](](
[![Coverage Status](](

-- **Still in beta** --

## Description
json rpc 2.0 protocol implementation for asyncio, without transport.


## Usage:
Example to resolve request:

import asyncio
import json

from aio_jsonrpc_20 import RequestResolver

async def foo(msg):
await asyncio.sleep(0.1)
return 'foobar ' + str(msg)

router = {'foo': foo}
resolver = RequestResolver(router)
json_request = json.dumps(
{"jsonrpc": "2.0", "method": "foo", "params": ["toto"], "id": 1}

async def main():
json_response = await resolver.handle(json_request)

loop = asyncio.get_event_loop()
{"jsonrpc": "2.0", "result": "foobar toto", "id": 1}

Example to build request:
from aio_jsonrpc_20 import RequestBuilder

builder = RequestBuilder()
json_request ="foo", params={"name": "bar"})
json_request ="foo", params={"name": "bar2"})
json_request = builder.notify(method="log", params=["hello"])

{"jsonrpc": "2.0", "method": "foo", "params": {"name": "bar"}, "id": 1}
{"jsonrpc": "2.0", "method": "foo", "params": {"name": "bar2"}, "id": 2}
{"jsonrpc": "2.0", "method": "log", "params": ["hello"]}


Example to build batch request:
from aio_jsonrpc_20 import BatchRequestBuilder

batch_builder = BatchRequestBuilder()
id1 ="foo", params={"name": "bar"})
id2 ="foo2", params={"name": "bar"})
print(id1, id2)
batch_builder.notify(method="foo3", params={"name": "bar"})
json_request = batch_builder.get_request()

1 2
{"jsonrpc": "2.0", "method": "foo", "params": {"name": "bar"}, "id": 1},
{"jsonrpc": "2.0", "method": "foo2", "params": {"name": "bar"}, "id": 2},
{"jsonrpc": "2.0", "method": "foo3", "params": {"name": "bar"}}

## TODO:
* Fix definitely interface for builders
* More Test
* Documentation
* Optimisation
* ...

## Testing:
py.test --cov=aio_jsonrpc_20 --cov-report term-missing tests/


Initial release.

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aio-jsonrpc-2.0, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size aio-jsonrpc-2.0-0.1.0.tar.gz (5.9 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 SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page