{ "info": { "author": "OGURA_Daiki", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3 :: Only" ], "description": "[![CircleCI](https://circleci.com/gh/hachibeeDI/py-json-rpc.svg?style=svg)](https://circleci.com/gh/hachibeeDI/py-json-rpc)\n\n# PY-JSON-RPC\n\nSimple and Pluggable JSON RPC toolkit to declare procedures super easy like Flask.\n\nPY-JSON-RPC supports async function handling!! It could improve your batch call performance.\n\n\n## Install\n\n```sh\n$ pip install py-json-rpc\n```\n\n\n## Sample\n\n\n### None async\n\nTornado is not a required. Just an sample to create HTTP handler. You can use other HTTP handling solution Flask, Django... if you would like to.\n\n```python\n\nimport json\n\nimport requests\nimport tornado.ioloop\nimport tornado.web\n\nfrom json_rpc import register, rpc_dispatcher, make_request\nfrom json_rpc.server.http import create_handler\n\n\n# define method very easy\n@register\ndef aa(aa):\n return aa + ' called'\n\n\n# you can appoint method name for rpc call\n@register('test/hyoe')\ndef hoge(x, y):\n return x + y\n\n\nif __name__ == '__main__':\n # you can call functions simply\n print(aa(aa='cc'))\n # => 'cc called'\n\n # you can call function via json rpc protocol\n rpc = rpc_dispatcher({\n 'jsonrpc': '2.0',\n 'method': 'aa',\n 'params': {'aa': 'rpc'},\n 'id': '111',\n })\n rpc2 = rpc_dispatcher(make_request('test/hyoe', {'x': 20, 'y': 10}))\n print(json.dumps(rpc))\n # => {\"jsonrpc\": \"2.0\", \"result\": \"cccc called\", \"id\": \"111\"}\n print(json.dumps(rpc))\n # => u'{\"jsonrpc\": \"2.0\", \"result\": \"cccc called\", \"id\": \"some_uuid_for_you\"}'\n\n # there is HTTP server to receive rpc call\n def make_app():\n return tornado.web.Application([\n (r'/rpc', create_handler(tornado.web.RequestHandler)),\n ])\n app = make_app()\n app.listen(8888)\n tornado.ioloop.IOLoop.current().start()\n\n \"\"\"\n example to make rpc request\n \"\"\"\n print(requests.post('http://localhost:8888/rpc', data=json.dumps(make_request('aa', {'aa': 'cccc '}))).text)\n # => {\"jsonrpc\": \"2.0\", \"result\": \"cccc called\", \"id\": \"some_uuid_for_you\"}\n print(requests.post('http://localhost:8888/rpc', data=json.dumps(make_request('test/hyoe', {'x': 3, 'y': 3}))).text)\n # => \"jsonrpc\": \"2.0\", \"result\": 6, \"id\": \"cff9667f-a520-42cf-9216-ef2fa051a213\"}\n\n```\n\n\n### Async\n\n\n```python\n\nloop = asyncio.get_event_loop()\napp = Registrator(loop=loop)\n\n\n@app.register\nasync def plus_rpc(x, y):\n return x + y\n\n\n@app.register\nasync def minus(x, y):\n return x - y\n\n\n@app.register\nasync def heavy_request(a):\n print(f'start heavy request... {a}sec')\n await asyncio.sleep(a)\n print('end heavy request...')\n return 'home page!'\n\n\n\"\"\"\nNo difference with none async version to call those functions.\nMore samples in test code. Document is under writing...\n\"\"\"\n\n\ndef test_plain():\n \"\"\"\n The func is going to be async as it was if it was called normally.\n \"\"\"\n result = asyncio.ensure_future(plus_rpc(1, 2))\n result = loop.run_until_complete(result)\n assert result == 3, result\n\n\ndef test_positional_rpc_call():\n rpc_result = app.dispatch({\n 'jsonrpc': '2.0',\n 'method': 'plus_rpc',\n 'params': [1, 2],\n 'id': 111,\n })\n assert rpc_result.get('result') == 3, rpc_result\n\n```\n\n\n### Integrate with Tornado\n\nYou can see `from json_rpc.server.http import create_handler` and the usage in the example on above. A function `create_handler` will create a handler instance for Tornado.\nPlease be aware that the instance haven't implement any security functionality. In case you'd like to a RPC end point to be public, you might want to consider create a handler by yourself (or feel free to open an issue ...or PR of course!).\n\n\n### Integrate with Flask\n\nSmall sample\n\n```python\nimport json\n\nfrom flask import Flask, request\nfrom json_rpc import register, rpc_dispatcher\n\n\napp = Flask(__name__)\n\n\n@register\ndef hoge(name):\n return f'{name} called'\n\n\n@app.route('/', methods=['POST'])\ndef hello():\n result = rpc_dispatcher(request.json)\n return json.dumps(result)\n```\n\nTo test:\n\n```python\n>>> print(requests.post('http://localhost:5000', json=make_request('hoge', ['cccc'])).text)\n```\n\n\n### Integrate with Django\n\nSee Flask. View can be integrate with this module easily.\n\n\n## Fully supports JSON RPC protocol\n\nList argument, named argument, notify, batch request and proper error codes.\n\n\n## Supported Python versions\n\nGreater than or equal to Python 3.6\n\n\n## Road Map\n\n- Security instruction\n\n- WebSocket sample\n\n- MQTT server or GNATS daemon sample", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/hachibeeDI/py-json-rpc", "keywords": "json rpc,asyncio", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "py-json-rpc", "package_url": "https://pypi.org/project/py-json-rpc/", "platform": "", "project_url": "https://pypi.org/project/py-json-rpc/", "project_urls": { "Homepage": "https://github.com/hachibeeDI/py-json-rpc" }, "release_url": "https://pypi.org/project/py-json-rpc/0.0.6/", "requires_dist": null, "requires_python": "", "summary": "Decorator based toolkit to use JSONRPC easy like Flask. Asyncio supported.", "version": "0.0.6" }, "last_serial": 3686709, "releases": { "0.0.3": [ { "comment_text": "", "digests": { "md5": "f0847e1da544e179d6b69215f7336b9d", "sha256": "749d0558d279730e833e279728bdf11768ec1a5db2f37130805f418f5c81010f" }, "downloads": -1, "filename": "py-json-rpc-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f0847e1da544e179d6b69215f7336b9d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4494, "upload_time": "2017-03-28T12:17:01", "url": "https://files.pythonhosted.org/packages/6d/5a/74fb11f14dfcb51db78f77e4e462613ee38fa943722e28cdc3a0e0446236/py-json-rpc-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "59cafec05261181357188fd8e3b05aa0", "sha256": "6c7f7a4434aa9dbd03c7f490c67e50d830ec4f2f0c5951202ce2f6f1deacbda2" }, "downloads": -1, "filename": "py-json-rpc-0.0.4.tar.gz", "has_sig": false, "md5_digest": "59cafec05261181357188fd8e3b05aa0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5132, "upload_time": "2018-01-04T12:17:33", "url": "https://files.pythonhosted.org/packages/1a/82/a379b5502e523bec405139cebad8c3a969e483bbff12dc32de8653a25508/py-json-rpc-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "88daed4969e94b6a8e38272b9de5a778", "sha256": "3f6b1be2205234c8493b36bf68ceb3fa1347a6b7068ad2b3420005465310df8a" }, "downloads": -1, "filename": "py-json-rpc-0.0.5.tar.gz", "has_sig": false, "md5_digest": "88daed4969e94b6a8e38272b9de5a778", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7804, "upload_time": "2018-01-28T05:11:15", "url": "https://files.pythonhosted.org/packages/72/f4/5e3ed71cf2ed20fb48e78722e16308570a6b233fa7fdeb60900fedb1f45c/py-json-rpc-0.0.5.tar.gz" } ], "0.0.6": [ { "comment_text": "", "digests": { "md5": "7276eca3f14a650485921e96b0e178d4", "sha256": "bb4e7f6e12b88ed97e1e236bb0bc62606f3f8808589e2405363f6c9c2bada1a2" }, "downloads": -1, "filename": "py-json-rpc-0.0.6.tar.gz", "has_sig": false, "md5_digest": "7276eca3f14a650485921e96b0e178d4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8013, "upload_time": "2018-03-20T07:06:04", "url": "https://files.pythonhosted.org/packages/f9/f7/ef67d2ed1aa194768071eaa2a23d09f5db6a76821b090a07b6ad9810a7b5/py-json-rpc-0.0.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7276eca3f14a650485921e96b0e178d4", "sha256": "bb4e7f6e12b88ed97e1e236bb0bc62606f3f8808589e2405363f6c9c2bada1a2" }, "downloads": -1, "filename": "py-json-rpc-0.0.6.tar.gz", "has_sig": false, "md5_digest": "7276eca3f14a650485921e96b0e178d4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8013, "upload_time": "2018-03-20T07:06:04", "url": "https://files.pythonhosted.org/packages/f9/f7/ef67d2ed1aa194768071eaa2a23d09f5db6a76821b090a07b6ad9810a7b5/py-json-rpc-0.0.6.tar.gz" } ] }