Skip to content
Simple extendable JSON-RPC Service builder / handler
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Simple extendable JSON-RPC Service builder and handler.


This library is supposed to run with Python 3. No other dependencies are needed.


from jsonrpcservice import Service, ApplicationError, Request

service = Service()
service.add_method("ping", lambda: "pong")

def what_is_foo():
    return "Foo is not bar."

def add(a, b):
    return a + b

def fail():
    raise ApplicationError(1200, "It was all in vain.")

request = Request(raw_request='{"jsonrpc": "2.0", "id": 321, "method": "foo"}')
response = service.handle_request(request)
response.body  # '{"jsonrpc":"2.0","id": 321,"result":"Foo is not bar."}'

request = Request(parsed_request={"jsonrpc": "2.0", "id": 321, "method": "add", "params": {"a": 5, "b": 13}})
response = service.handle_request(request)
response.dict  # {"jsonrpc": "2.0", "id": 321, "result": 18}

request = Request(parsed_request={"jsonrpc": "2.0", "id": 321, "method": "fail"})
response = service.handle_request(request)
response.dict  # {"jsonrpc": "2.0", "id": 321, "error": {"code": 1200, "message": "It was all in vain."}}

For more examples and documentation see docstrings.

Running the tests

python3 -m unittest


This project is licensed under the MIT License - see the LICENSE file for details

You can’t perform that action at this time.