{"id":21203234,"url":"https://github.com/mon4ter/sanic-jsonrpc","last_synced_at":"2025-07-10T06:33:59.543Z","repository":{"id":45942899,"uuid":"195508750","full_name":"mon4ter/sanic-jsonrpc","owner":"mon4ter","description":"JSON-RPC 2.0 support for Sanic over HTTP and WebSocket","archived":false,"fork":false,"pushed_at":"2021-11-25T20:44:43.000Z","size":209,"stargazers_count":8,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-23T21:21:40.539Z","etag":null,"topics":["jsonrpc","sanic","websocket"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mon4ter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-06T07:00:51.000Z","updated_at":"2022-09-10T06:50:16.000Z","dependencies_parsed_at":"2022-09-26T21:31:43.785Z","dependency_job_id":null,"html_url":"https://github.com/mon4ter/sanic-jsonrpc","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mon4ter%2Fsanic-jsonrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mon4ter%2Fsanic-jsonrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mon4ter%2Fsanic-jsonrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mon4ter%2Fsanic-jsonrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mon4ter","download_url":"https://codeload.github.com/mon4ter/sanic-jsonrpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225624369,"owners_count":17498419,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsonrpc","sanic","websocket"],"created_at":"2024-11-20T20:22:37.665Z","updated_at":"2024-11-20T20:22:38.248Z","avatar_url":"https://github.com/mon4ter.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sanic-jsonrpc\n[![PyPI version](https://img.shields.io/pypi/v/sanic-jsonrpc.svg)](https://pypi.org/project/sanic-jsonrpc)\n[![Python version](https://img.shields.io/pypi/pyversions/sanic-jsonrpc.svg)](https://pypi.org/project/sanic-jsonrpc)\n[![Build Status](https://travis-ci.org/mon4ter/sanic-jsonrpc.svg?branch=master)](https://travis-ci.org/mon4ter/sanic-jsonrpc)\n[![codecov](https://codecov.io/gh/mon4ter/sanic-jsonrpc/branch/master/graph/badge.svg)](https://codecov.io/gh/mon4ter/sanic-jsonrpc)\n\nJSON-RPC 2.0 support for Sanic over HTTP and WebSocket\n\n## Features\n\n* Complete JSON-RPC 2.0 Specification implementation, including [batch](https://www.jsonrpc.org/specification#batch)\n* Annotation based type validation\n* Request and/or Notification routing\n* Conditional middleware\n* Exception handlers\n* Server side Notifications\n* Access to app and request objects via annotation\n\n## Example\n\n### server.py\n```python\nfrom sanic import Sanic\nfrom sanic_jsonrpc import SanicJsonrpc\n\napp = Sanic('server')\njsonrpc = SanicJsonrpc(app, post_route='/api/rpc/post', ws_route='/api/rpc/ws')\n\n@jsonrpc\ndef sub(a: int, b: int) -\u003e int:\n    return a - b\n\nif __name__ == '__main__':\n    app.run(host='127.0.0.1', port=8000)\n```\n\n### client.py\n```python\nfrom asyncio import get_event_loop\n\nfrom aiohttp import ClientSession\n\nasync def main():\n    url = 'http://127.0.0.1:8000/api/rpc'\n    request = {'jsonrpc': '2.0', 'method': 'sub', 'params': [42, 23], 'id': 1}\n\n    async with ClientSession() as session:\n        async with session.post(url + '/post', json=request) as resp:\n            response = await resp.json()\n            print(response['result'])  # 19\n\n        async with session.ws_connect(url + '/ws') as ws:\n            await ws.send_json(request)\n            response = await ws.receive_json()\n            print(response['result'])  # 19\n\nif __name__ == '__main__':\n    get_event_loop().run_until_complete(main())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmon4ter%2Fsanic-jsonrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmon4ter%2Fsanic-jsonrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmon4ter%2Fsanic-jsonrpc/lists"}