Skip to main content

json-rpc

Build Status Coverage Status https://readthedocs.org/projects/json-rpc/badge/?version=latest Latest PyPI version Supported Python versions Gitter Bakers Sponsors

JSON-RPC2.0 and JSON-RPC1.0 transport specification implementation. Supports Python 2.6+, Python 3.3+, PyPy. Has optional Django and Flask support. 200+ tests.

Features

This implementation does not have any transport functionality realization, only protocol. Any client or server implementation is easy based on current code, but requires transport libraries, such as requests, gevent or zmq, see examples.

  • Vanilla Python, no dependencies.

  • 200+ tests for multiple edge cases.

  • Optional backend support for Django, Flask.

  • json-rpc 1.1 and 2.0 support.

Install

pip install json-rpc

Tests

Quickstart

This is an essential part of the library as there are a lot of edge cases in JSON-RPC standard. To manage a variety of supported python versions as well as optional backends json-rpc uses tox:

tox

Continuous integration

This project uses CircleCI for continuous integration. All of the python supported versions are managed via tox.ini and .circleci/config.yml files. Master branch test status is displayed on the badge in the beginning of this document.

Test matrix

json-rpc supports multiple python versions: 2.6+, 3.3+, pypy. This introduces difficulties with testing libraries and optional dependencies management. For example, python before version 3.3 does not support mock and there is a limited support for unittest2. Every dependency translates into if-then blocks in the source code and adds complexity to it. Hence, while cross-python support is a core feature of this library, cross-Django or cross-Flask support is limited. In general, json-rpc uses latest stable release which supports current python version. For example, python 2.6 is compatible with Django 1.6 and not compatible with any future versions.

Below is a testing matrix:

Python

mock

unittest

Django

Flask

2.6

2.0.0

unittest2

1.6

0.12.2

2.7

2.0.0

1.11

0.12.2

3.3

1.11

0.12.2

3.4

1.11

0.12.2

3.5

1.11

0.12.2

3.6

1.11

0.12.2

pypy

2.0.0

1.11

0.12.2

pypy3

1.11

0.12.2

Quickstart

Server (uses Werkzeug)

from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple

from jsonrpc import JSONRPCResponseManager, dispatcher


@dispatcher.add_method
def foobar(**kwargs):
    return kwargs["foo"] + kwargs["bar"]


@Request.application
def application(request):
    # Dispatcher is dictionary {<method_name>: callable}
    dispatcher["echo"] = lambda s: s
    dispatcher["add"] = lambda a, b: a + b

    response = JSONRPCResponseManager.handle(
        request.data, dispatcher)
    return Response(response.json, mimetype='application/json')


if __name__ == '__main__':
    run_simple('localhost', 4000, application)

Client (uses requests)

import requests
import json


def main():
    url = "http://localhost:4000/jsonrpc"

    # Example echo method
    payload = {
        "method": "echo",
        "params": ["echome!"],
        "jsonrpc": "2.0",
        "id": 0,
    }
    response = requests.post(url, json=payload).json()

    assert response["result"] == "echome!"
    assert response["jsonrpc"]
    assert response["id"] == 0

if __name__ == "__main__":
    main()

Competitors

There are several libraries implementing JSON-RPC protocol. List below represents python libraries, none of the supports python3. tinyrpc looks better than others.

Metadata

Release files for json-rpc 1.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json-rpc 1.15.0
File Size Uploaded
json-rpc-1.15.0.tar.gz 28.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json-rpc 1.15.0
File Interpreter ABI Platform
json_rpc-1.15.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 68.3 kB

Release files / json-rpc-1.15.0.tar.gz

Download URL json-rpc-1.15.0.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e6441d56c1dcd54241c937d0a2dcd193bdf0bdc539b5316524713f554b7f85b9
BLAKE2b-256 checksum
How to use checksums
6d9e59f4a5b7855ced7346ebf40a2e9a8942863f644378d956f68bcef2c88b90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release files / json_rpc-1.15.0-py2.py3-none-any.whl

Download URL json_rpc-1.15.0-py2.py3-none-any.whl
Size 39.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4a4668bbbe7116feb4abbd0f54e64a4adcf4b8f648f19ffa0848ad0f6606a9bf
BLAKE2b-256 checksum
How to use checksums
949e820c4b086ad01ba7d77369fb8b11470a01fac9b4977f02e18659cf378b6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.15.0 This release

2 release files

1.14.0

2 release files

1.12.2

2 release files

1.12.1

2 release files

1.11.1

2 release files

1.10.7

2 release files

1.10.6

2 release files

1.10.5

2 release files

1.10.4

2 release files

1.10.1

2 release files

1.9.2

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.4

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

3 release files

1.4.0

3 release files

1.3.0

3 release files

1.2.1

1 release file

1.2

1 release file

1.1

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.0

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page