Package: json-rpc
JSON-RPC2.0andJSON-RPC1.0transport specification implementation.
Supports Python 2.6+, Python 3.3+, PyPy. Has optional Django and Flask support. 200+ tests.FeaturesThis 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, seeexamples.Vanilla Python, no dependencies.200+ tests for multiple edge cases.Optional backend support for Django, Flask.json-rpc 1.1 and 2.0 support.Installpipinstalljson-rpcTestsQuickstartThis 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 usestox:toxTipDuring local development use your python version with tox runner. For example, if your are using Python 3.6 runtox -e py36. It is easier to develop functionality for specific version first and then expands it to all of the supported versions.Continuous integrationThis project usesCircleCIfor continuous integration. All of the python supported versions are managed viatox.iniand.circleci/config.ymlfiles. Master branch test status is displayed on the badge in the beginning of this document.Test matrixjson-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 supportmockand there is a limited support forunittest2. Every dependency translates intoif-thenblocks 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:PythonmockunittestDjangoFlask2.62.0.0unittest21.60.12.22.72.0.01.110.12.23.31.110.12.23.41.110.12.23.51.110.12.23.61.110.12.2pypy2.0.01.110.12.2pypy31.110.12.2QuickstartServer (usesWerkzeug)fromwerkzeug.wrappersimportRequest,Responsefromwerkzeug.servingimportrun_simplefromjsonrpcimportJSONRPCResponseManager,dispatcher@dispatcher.add_methoddeffoobar(**kwargs):returnkwargs["foo"]+kwargs["bar"]@Request.applicationdefapplication(request):# Dispatcher is dictionary {<method_name>: callable}dispatcher["echo"]=lambdas:sdispatcher["add"]=lambdaa,b:a+bresponse=JSONRPCResponseManager.handle(request.data,dispatcher)returnResponse(response.json,mimetype='application/json')if__name__=='__main__':run_simple('localhost',4000,application)Client (usesrequests)importrequestsimportjsondefmain():url="http://localhost:4000/jsonrpc"# Example echo methodpayload={"method":"echo","params":["echome!"],"jsonrpc":"2.0","id":0,}response=requests.post(url,json=payload).json()assertresponse["result"]=="echome!"assertresponse["jsonrpc"]assertresponse["id"]==0if__name__=="__main__":main()CompetitorsThere areseveral librariesimplementing JSON-RPC protocol. List below represents python libraries, none of the supports python3. tinyrpc looks better than others.