json-rpc


Namejson-rpc JSON
Version 1.15.0 PyPI version JSON
download
home_pagehttps://github.com/pavlov99/json-rpc
SummaryJSON-RPC transport implementation
upload_time2023-06-11 09:45:49
maintainer
docs_urlNone
authorKirill Pavlov
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            json-rpc
========

.. image:: https://circleci.com/gh/pavlov99/json-rpc/tree/master.svg?style=svg
    :target: https://circleci.com/gh/pavlov99/json-rpc/tree/master
    :alt: Build Status

.. image:: https://codecov.io/gh/pavlov99/json-rpc/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/pavlov99/json-rpc
    :alt: Coverage Status

.. image:: https://readthedocs.org/projects/json-rpc/badge/?version=latest
    :target: http://json-rpc.readthedocs.io/en/latest/?badge=latest

.. image:: https://img.shields.io/pypi/v/json-rpc.svg
    :target: https://pypi.org/project/json-rpc/
    :alt: Latest PyPI version

.. image:: https://img.shields.io/pypi/pyversions/json-rpc.svg
    :target: https://pypi.org/project/json-rpc/
    :alt: Supported Python versions

.. image:: https://badges.gitter.im/pavlov99/json-rpc.svg
    :target: https://gitter.im/pavlov99/json-rpc
    :alt: Gitter


.. image:: https://opencollective.com/json-rpc/tiers/backer/badge.svg?label=backer&color=brightgreen
    :target: https://opencollective.com/json-rpc
    :alt: Bakers

.. image:: https://opencollective.com/json-rpc/tiers/backer/badge.svg?label=sponsor&color=brightgreen
    :target: https://opencollective.com/json-rpc
    :alt: Sponsors

`JSON-RPC2.0 <http://www.jsonrpc.org/specification>`_ and `JSON-RPC1.0 <http://json-rpc.org/wiki/specification>`_ 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 <https://github.com/pavlov99/json-rpc/tree/master/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
-------

.. code-block:: python

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

.. code-block:: bash

    tox

.. TIP::
   During local development use your python version with tox runner. For example, if your are using Python 3.6 run `tox -e py36`. It is easier to develop functionality for specific version first and then expands it to all of the supported versions.

Continuous integration
^^^^^^^^^^^^^^^^^^^^^^
This project uses `CircleCI <https://circleci.com/>`_ 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 <http://werkzeug.pocoo.org/>`_)

.. code-block:: python

    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 <http://www.python-requests.org/en/latest/>`_)

.. code-block:: python

    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 <http://en.wikipedia.org/wiki/JSON-RPC#Implementations>`_ implementing JSON-RPC protocol. List below represents python libraries, none of the supports python3. tinyrpc looks better than others.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pavlov99/json-rpc",
    "name": "json-rpc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Kirill Pavlov",
    "author_email": "k@p99.io",
    "download_url": "https://files.pythonhosted.org/packages/6d/9e/59f4a5b7855ced7346ebf40a2e9a8942863f644378d956f68bcef2c88b90/json-rpc-1.15.0.tar.gz",
    "platform": null,
    "description": "json-rpc\n========\n\n.. image:: https://circleci.com/gh/pavlov99/json-rpc/tree/master.svg?style=svg\n    :target: https://circleci.com/gh/pavlov99/json-rpc/tree/master\n    :alt: Build Status\n\n.. image:: https://codecov.io/gh/pavlov99/json-rpc/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/pavlov99/json-rpc\n    :alt: Coverage Status\n\n.. image:: https://readthedocs.org/projects/json-rpc/badge/?version=latest\n    :target: http://json-rpc.readthedocs.io/en/latest/?badge=latest\n\n.. image:: https://img.shields.io/pypi/v/json-rpc.svg\n    :target: https://pypi.org/project/json-rpc/\n    :alt: Latest PyPI version\n\n.. image:: https://img.shields.io/pypi/pyversions/json-rpc.svg\n    :target: https://pypi.org/project/json-rpc/\n    :alt: Supported Python versions\n\n.. image:: https://badges.gitter.im/pavlov99/json-rpc.svg\n    :target: https://gitter.im/pavlov99/json-rpc\n    :alt: Gitter\n\n\n.. image:: https://opencollective.com/json-rpc/tiers/backer/badge.svg?label=backer&color=brightgreen\n    :target: https://opencollective.com/json-rpc\n    :alt: Bakers\n\n.. image:: https://opencollective.com/json-rpc/tiers/backer/badge.svg?label=sponsor&color=brightgreen\n    :target: https://opencollective.com/json-rpc\n    :alt: Sponsors\n\n`JSON-RPC2.0 <http://www.jsonrpc.org/specification>`_ and `JSON-RPC1.0 <http://json-rpc.org/wiki/specification>`_ transport specification implementation.\nSupports Python 2.6+, Python 3.3+, PyPy. Has optional Django and Flask support. 200+ tests.\n\nFeatures\n--------\n\nThis implementation does not have any transport functionality realization, only protocol.\nAny client or server implementation is easy based on current code, but requires transport libraries, such as requests, gevent or zmq, see `examples <https://github.com/pavlov99/json-rpc/tree/master/examples>`_.\n\n- Vanilla Python, no dependencies.\n- 200+ tests for multiple edge cases.\n- Optional backend support for Django, Flask.\n- json-rpc 1.1 and 2.0 support.\n\nInstall\n-------\n\n.. code-block:: python\n\n    pip install json-rpc\n\nTests\n-----\n\nQuickstart\n^^^^^^^^^^\nThis 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`:\n\n.. code-block:: bash\n\n    tox\n\n.. TIP::\n   During local development use your python version with tox runner. For example, if your are using Python 3.6 run `tox -e py36`. It is easier to develop functionality for specific version first and then expands it to all of the supported versions.\n\nContinuous integration\n^^^^^^^^^^^^^^^^^^^^^^\nThis project uses `CircleCI <https://circleci.com/>`_ 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.\n\nTest matrix\n^^^^^^^^^^^\njson-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.\n\nBelow is a testing matrix:\n\n+--------+-------+-----------+--------+--------+\n| Python | mock  | unittest  | Django | Flask  |\n+========+=======+===========+========+========+\n| 2.6    | 2.0.0 | unittest2 | 1.6    | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n| 2.7    | 2.0.0 |           | 1.11   | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n| 3.3    |       |           | 1.11   | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n| 3.4    |       |           | 1.11   | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n| 3.5    |       |           | 1.11   | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n| 3.6    |       |           | 1.11   | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n| pypy   | 2.0.0 |           | 1.11   | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n| pypy3  |       |           | 1.11   | 0.12.2 |\n+--------+-------+-----------+--------+--------+\n\nQuickstart\n----------\nServer (uses `Werkzeug <http://werkzeug.pocoo.org/>`_)\n\n.. code-block:: python\n\n    from werkzeug.wrappers import Request, Response\n    from werkzeug.serving import run_simple\n\n    from jsonrpc import JSONRPCResponseManager, dispatcher\n\n\n    @dispatcher.add_method\n    def foobar(**kwargs):\n        return kwargs[\"foo\"] + kwargs[\"bar\"]\n\n\n    @Request.application\n    def application(request):\n        # Dispatcher is dictionary {<method_name>: callable}\n        dispatcher[\"echo\"] = lambda s: s\n        dispatcher[\"add\"] = lambda a, b: a + b\n\n        response = JSONRPCResponseManager.handle(\n            request.data, dispatcher)\n        return Response(response.json, mimetype='application/json')\n\n\n    if __name__ == '__main__':\n        run_simple('localhost', 4000, application)\n\nClient (uses `requests <http://www.python-requests.org/en/latest/>`_)\n\n.. code-block:: python\n\n    import requests\n    import json\n\n\n    def main():\n        url = \"http://localhost:4000/jsonrpc\"\n\n        # Example echo method\n        payload = {\n            \"method\": \"echo\",\n            \"params\": [\"echome!\"],\n            \"jsonrpc\": \"2.0\",\n            \"id\": 0,\n        }\n        response = requests.post(url, json=payload).json()\n\n        assert response[\"result\"] == \"echome!\"\n        assert response[\"jsonrpc\"]\n        assert response[\"id\"] == 0\n\n    if __name__ == \"__main__\":\n        main()\n\nCompetitors\n-----------\nThere are `several libraries <http://en.wikipedia.org/wiki/JSON-RPC#Implementations>`_ implementing JSON-RPC protocol. List below represents python libraries, none of the supports python3. tinyrpc looks better than others.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "JSON-RPC transport implementation",
    "version": "1.15.0",
    "project_urls": {
        "Homepage": "https://github.com/pavlov99/json-rpc"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "949e820c4b086ad01ba7d77369fb8b11470a01fac9b4977f02e18659cf378b6b",
                "md5": "0585f954335dddb566ed03157477f4ab",
                "sha256": "4a4668bbbe7116feb4abbd0f54e64a4adcf4b8f648f19ffa0848ad0f6606a9bf"
            },
            "downloads": -1,
            "filename": "json_rpc-1.15.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0585f954335dddb566ed03157477f4ab",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 39450,
            "upload_time": "2023-06-11T09:45:47",
            "upload_time_iso_8601": "2023-06-11T09:45:47.136649Z",
            "url": "https://files.pythonhosted.org/packages/94/9e/820c4b086ad01ba7d77369fb8b11470a01fac9b4977f02e18659cf378b6b/json_rpc-1.15.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d9e59f4a5b7855ced7346ebf40a2e9a8942863f644378d956f68bcef2c88b90",
                "md5": "d583cd50691f92229b0217946037d17d",
                "sha256": "e6441d56c1dcd54241c937d0a2dcd193bdf0bdc539b5316524713f554b7f85b9"
            },
            "downloads": -1,
            "filename": "json-rpc-1.15.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d583cd50691f92229b0217946037d17d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 28854,
            "upload_time": "2023-06-11T09:45:49",
            "upload_time_iso_8601": "2023-06-11T09:45:49.078282Z",
            "url": "https://files.pythonhosted.org/packages/6d/9e/59f4a5b7855ced7346ebf40a2e9a8942863f644378d956f68bcef2c88b90/json-rpc-1.15.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-11 09:45:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pavlov99",
    "github_project": "json-rpc",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": false,
    "circle": true,
    "tox": true,
    "lcname": "json-rpc"
}
        
Elapsed time: 0.07609s