{"id":19651646,"url":"https://github.com/crimson-crow/pyjsonrpc2","last_synced_at":"2026-02-22T07:34:19.221Z","repository":{"id":262035402,"uuid":"523034470","full_name":"Crimson-Crow/pyjsonrpc2","owner":"Crimson-Crow","description":"A flexible Python implementation of the JSON-RPC 2.0 protocol","archived":false,"fork":false,"pushed_at":"2024-11-10T07:33:08.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-30T03:57:54.071Z","etag":null,"topics":["json","jsonrpc","jsonrpc-client","jsonrpc-server","rpc"],"latest_commit_sha":null,"homepage":"","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/Crimson-Crow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-09T16:50:16.000Z","updated_at":"2024-11-10T07:33:12.000Z","dependencies_parsed_at":"2025-04-30T19:43:48.339Z","dependency_job_id":"9000e3c1-48c0-4527-a396-67cca59385d0","html_url":"https://github.com/Crimson-Crow/pyjsonrpc2","commit_stats":null,"previous_names":["crimson-crow/pyjsonrpc","crimson-crow/pyjsonrpc2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Crimson-Crow/pyjsonrpc2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crimson-Crow%2Fpyjsonrpc2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crimson-Crow%2Fpyjsonrpc2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crimson-Crow%2Fpyjsonrpc2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crimson-Crow%2Fpyjsonrpc2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Crimson-Crow","download_url":"https://codeload.github.com/Crimson-Crow/pyjsonrpc2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Crimson-Crow%2Fpyjsonrpc2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29706569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T05:59:28.568Z","status":"ssl_error","status_checked_at":"2026-02-22T05:58:46.208Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["json","jsonrpc","jsonrpc-client","jsonrpc-server","rpc"],"created_at":"2024-11-11T15:07:18.657Z","updated_at":"2026-02-22T07:34:19.192Z","avatar_url":"https://github.com/Crimson-Crow.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyjsonrpc2\n\n[![PyPI](https://img.shields.io/pypi/v/pyjsonrpc2)](https://pypi.org/project/pyjsonrpc2/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyjsonrpc2)](https://pypi.org/project/pyjsonrpc2/)\n[![GitHub](https://img.shields.io/github/license/Crimson-Crow/pyjsonrpc2)](https://github.com/Crimson-Crow/pyjsonrpc2/blob/main/LICENSE.txt)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://makeapullrequest.com)\n\nA flexible Python implementation of the JSON-RPC 2.0 protocol (currently server-side only).\n\n## Key features\n- Full compliance with the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification)\n- No transport functionality\n- Multiple method registration patterns (class-based, individual methods, lambda, etc.)\n- Automatic \u0026 custom error handling capabilities\n- Support for both string and bytes input\n- Complete type hints (passes `mypy --strict`)\n- Extensive unit tests (full coverage)\n- [Semantic versioning](https://semver.org/) adherence\n\n## Installation\n\nTo install the package, use [pip](https://pip.pypa.io/en/stable/):\n\n```bash\npip install pyjsonrpc2\n```\n\n## Usage\n\nFor more info, check the `/examples` directory.\n\n### Basic Server Creation\n\n```python\nfrom pyjsonrpc2.server import JsonRpcServer, rpc_method, JsonRpcError\n\n# Create a basic server\nserver = JsonRpcServer()\n```\n\n### Method Registration Patterns\n\nThese are the main patterns for registering RPC methods. `/examples/registering_methods.py` contains a few more.\n1. Class-based approach with decorators:\n```python\nclass MathServer(JsonRpcServer):\n    @rpc_method\n    def square(self, x):\n        return x**2\n\n    @rpc_method(name=\"cube\")\n    def calculate_cube(self, x):\n        return x**3\n\nserver = MathServer()\n```\n\n2. Adding individual methods using decorators:\n```python\n@server.add_method\ndef add(a, b):\n    return a + b\n```\n\n3. Adding methods with custom names:\n```python\ndef sub(a, b):\n    return a - b\n\nserver.add_method(sub, name=\"substract\")\n```\n\n4. Adding lambda functions:\n```python\nserver.add_method(lambda a, b: a % b, name=\"modulo\")\n```\n\n### Error Handling\nError handling features:\n- Custom error codes for implementation-defined \u0026 application-defined errors through the `JsonRpcError` class\n- Automatic conversion of Python exceptions to JSON-RPC Internal error responses\n- Support for additional error data in a structured format\n- Built-in handling of protocol-level errors (invalid JSON, missing required fields, etc.)\n- Error logging for debugging purposes\n\n1. Custom Implementation-Defined Errors:\n```python\nclass AdvancedMathServer(JsonRpcServer):\n    @rpc_method\n    def divide(self, a, b):\n        if b == 0:\n            raise JsonRpcError(\n                code=-32000,\n                message=\"Division by zero\",\n                data={\"numerator\": a, \"denominator\": b}\n            )\n        return a / b\n```\n\n2. Multiple Error Conditions:\n```python\n@rpc_method\ndef factorial(self, n):\n    if not isinstance(n, int):\n        # Regular exceptions are caught and converted to Internal error responses\n        raise TypeError(\"n must be an integer\")\n\n    if n \u003c 0:\n        # Custom JSON-RPC errors with additional data\n        raise JsonRpcError(\n            code=-32001,\n            message=\"Invalid input for factorial\",\n            data={\"input\": n, \"reason\": \"Must be non-negative\"}\n        )\n    # ... implementation ...\n```\n\n### Request execution\n```python\nresult = server.call('{\"jsonrpc\": \"2.0\", \"method\": \"add\", \"params\": [5, 3], \"id\": 1}')\nresult = server.call(b'{\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": [5, 3], \"id\": 2}')\n```\n\n## Tests\n\nThe simplest way to run tests is:\n\n```bash\npython -m unittest\n```\n\nAs a more robust alternative, you can install [`tox`](https://tox.wiki) to automatically test across the supported python versions, then run:\n\n```bash\ntox -p\n```\n\n## Issue tracker\n\nPlease report any bugs or enhancement ideas using the [issue tracker](https://github.com/Crimson-Crow/pyjsonrpc2/issues).\n\n## License\n\n`pyjsonrpc2` is licensed under the terms of the [MIT License](https://github.com/Crimson-Crow/pyjsonrpc2/blob/main/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrimson-crow%2Fpyjsonrpc2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrimson-crow%2Fpyjsonrpc2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrimson-crow%2Fpyjsonrpc2/lists"}