This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

JSON-RPC transport realisation

Project Description

JSON-RPC2.0 and JSON-RPC1.0 transport specification implementation. Supports python2.6+, python3.3+, PyPy. Has optional Django and Flask support. 200+ tests.

Documentation: http://json-rpc.readthedocs.org

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

Install

pip install json-rpc

Tests

tox

Features

  • Vanilla python, no dependencies
  • Optional backend support for Django, Flask
  • json-rpc 1.1 and 2.0 support

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"
    headers = {'content-type': 'application/json'}

    # Example echo method
    payload = {
        "method": "echo",
        "params": ["echome!"],
        "jsonrpc": "2.0",
        "id": 0,
    }
    response = requests.post(
        url, data=json.dumps(payload), headers=headers).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.

Testing

json-rpc is a python library, it supports pythons: 2.6, 2.7, 3.3, 3.4. There is optional support for django1.6 (python2.6 does not support django1.7).

Contributors

Release History

Release History

This version
History Node

1.10.3

History Node

1.10.2

History Node

1.10.1

History Node

1.9.2

History Node

1.9.1

History Node

1.9.0

History Node

1.8.4

History Node

1.8.3

History Node

1.8.2

History Node

1.8.1

History Node

1.8.0

History Node

1.7.0

History Node

1.6.0

History Node

1.5.0

History Node

1.4.0

History Node

1.3.0

History Node

1.2.1

History Node

1.2

History Node

1.1

History Node

1.1.rc2

History Node

1.1.rc1

History Node

1.0.6

History Node

1.0.5

History Node

1.0.4

History Node

1.0.3

History Node

1.0.2

History Node

1.0.1

History Node

1.0.0

History Node

0.9.3

History Node

0.9.2

History Node

0.9.1

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2

History Node

0.1.0

History Node

0.1

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
json_rpc-1.10.3-py2.py3-none-any.whl (38.0 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Feb 2, 2016
json-rpc-1.10.3.tar.gz (27.3 kB) Copy SHA256 Checksum SHA256 Source Feb 2, 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