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 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

Tests are an essential part of the library, as there are a lot of edge cases in the JSON-RPC standard. Run them with pytest; Django and Flask backend tests are skipped if those frameworks are not installed:

pip install pytest django flask
make test

The full matrix of Python versions runs in CI only; locally, testing with a single interpreter is enough.

Continuous integration

This project uses GitHub Actions for continuous integration, configured in .github/workflows/tests.yml. Every push to master and every pull request is tested on CPython 2.7 and 3.6–3.14, PyPy 2.7 and PyPy 3, each in its official Docker image. A separate job builds the sdist and wheel, validates them with twine check, and runs the test suite against the installed wheel.

Each job installs the newest pytest, Django and Flask releases that still support that interpreter, so cross-Django and cross-Flask support follows what each Python version can run. The exact versions are printed in the “Show versions” step of every job.

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.2

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.2
File Size Uploaded Provenance Actions
json_rpc-1.15.2.tar.gz 37.3 kB Without provenance Details for json_rpc-1.15.2.tar.gz

Built distribution (wheel)

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

Total release size: 86.9 kB

Release files / json_rpc-1.15.2.tar.gz

Download URL json_rpc-1.15.2.tar.gz
Size 37.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e0e12cd1327d9c743eacc21aeedf432ba31b25792d46a749d850c76dc99c97d4
BLAKE2b-256 checksum
How to use checksums
742d3942cd7052da88f0ef3eacdc185b8fdc82becdb81768dea5249ea878740e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

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

Download URL json_rpc-1.15.2-py2.py3-none-any.whl
Size 49.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
01c1246f66542b70a8aa1979ddf45b6ded94fc1949ecb53b9f027fcf2bdf712f
BLAKE2b-256 checksum
How to use checksums
3b36ddf8b0662258925505bf4c0645af62628a8ca0f3b28063bc852ab844a70c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for json-rpc 1.15.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.15.2 This release

2 release files No provenance

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