Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

JSON RPC protocol for aiohttp.web (http server for asyncio)

Project Description


jsonrpc protocol implementation for aiohttp.web.

Example server

import asyncio
from aiohttp import web
from aiohttp_jrpc import Service, JError, jrpc_errorhandler_middleware

SCH = {
    "type": "object",
    "properties": {
        "data": {"type": "string"},

def custom_errorhandler_middleware(app, handler):
    def middleware(request):
            return (yield from handler(request))
        except Exception:
            """ Custom errors: -32000 to -32099 """
            return JError().custom(-32000, "Example error")
    return middleware

class MyJRPC(Service):
    def hello(self, ctx, data):
        if data["data"] == "hello":
            return {"status": "hi"}
        return {"status": data}

    def error(self, ctx, data):
        raise Exception("Error which will catch middleware")

    def no_valid(self, ctx, data):
        """ Method without validation incommig data """
        return {"status": "ok"}

def init(loop):
    app = web.Application(loop=loop, middlewares=[jrpc_errorhandler_middleware])
    #app = web.Application(loop=loop, middlewares=[custom_errorhandler_middleware])
    app.router.add_route('POST', "/api", MyJRPC)

    srv = yield from loop.create_server(app.make_handler(),
                                        "", 8080)
    print("Server started at")
    return srv

loop = asyncio.get_event_loop()
except KeyboardInterrupt:

Example client

import asyncio
import aiohttp
from aiohttp_jrpc import Client,InvalidResponse

Remote = Client('http://localhost:8080/api')

def rpc_call():
        rsp = yield from Remote.request('hello', {'data': 'hello'})
        return rsp
    except InvalidResponse as err:
        return err
    except Exception as err:
        return err
    return False

loop = asyncio.get_event_loop()
content = loop.run_until_complete(rpc_call())


aiohttp_jrpc BSD license.


0.1.0 (2016-02-20)

  • Added client and tests
  • Changed BSD v3 to BSD v2 license

0.0.3 (2015-10-27)

  • Fix messages of protocol errors
  • Fix tests and add tests for custom errors
  • Fix example bugs
  • Added custom middleware to example for handle errors

0.0.2 (2015-10-22)

  • Added middleware to catch exceptions
  • Testing internal error

0.0.1 (2015-10-18)

  • Init release


aiohttp_jrpc is written by Veniamin Gvozdikov.


Please add yourself here alphabetically when you submit your first pull request.

Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
aiohttp_jrpc-0.1.0-py3-none-any.whl (8.0 kB) Copy SHA256 Checksum SHA256 py3 Wheel Feb 24, 2016
aiohttp_jrpc-0.1.0.tar.gz (5.2 kB) Copy SHA256 Checksum SHA256 Source Feb 24, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting