jrpc-core
A lightweight, type-safe Python implementation of the JSON-RPC 2.0 specification.
jrpc-core provides two core layers:
| Layer | Module | Purpose |
|---|---|---|
| Messages | jrpc_core.messages |
Pydantic models for requests, responses, notifications, and errors |
| Dispatcher | jrpc_core.dispatcher |
Async registry-based routing of incoming messages to handler callables |
Table of Contents
Features
- Type-safe — every model is a Pydantic
BaseModelwith explicit field types and validators. - Functional — error handling uses
ResultandOptionfrom pyfplib instead of exceptions. - Lightweight — only depends on
pydanticandpyfplib, no async runtime required. - Serialisable — round-trips cleanly between Python objects and JSON strings.
- Extensible — custom response constructors, parameter validators, and converters.
Quick Start
import asyncio
from jrpc_core import JsonRpcRequest, JsonRpcDispatcher, JsonRpcMethodWrapper
# Create a request
request = JsonRpcRequest(method="add", params=[1, 2])
print(request.to_json())
# {"jsonrpc":"2.0","method":"add","params":[1,2],"id":"<uuid>"}
# Parse incoming JSON-RPC message
from jrpc_core import try_parse
result = try_parse('{"jsonrpc":"2.0","method":"add","params":[1,2],"id":"1"}')
# Use the dispatcher
async def main():
dispatcher = JsonRpcDispatcher()
dispatcher.request_handler_registry.add(
JsonRpcMethodWrapper(name="add", method=lambda args: args[0] + args[1])
)
response = await dispatcher(JsonRpcRequest(method="add", params=[1, 2], id=1))
print(response.unwrap().unwrap().result) # 3
asyncio.run(main())
Documentation
Installation
pip install jrpc-core
License
jrpc-core is distributed under the terms of the MIT license.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jrpc_core-0.1.1.tar.gz
(636.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
jrpc_core-0.1.1-py3-none-any.whl
(14.4 kB
view details)
File details
Details for the file jrpc_core-0.1.1.tar.gz.
File metadata
- Download URL: jrpc_core-0.1.1.tar.gz
- Upload date:
- Size: 636.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
Hatch/1.16.3 cpython/3.14.0 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e999d7a378c7a46b2718dcf4b01581f13c97ba1c5d5ec853c91a3b1c52d3fcef
|
|
| MD5 |
8b9c511cfa155015189ac2c2935769ab
|
|
| BLAKE2b-256 |
3704651c716f433ade7976992e13e4d4b21221752c35eecfcf477790b2991245
|
File details
Details for the file jrpc_core-0.1.1-py3-none-any.whl.
File metadata
- Download URL: jrpc_core-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
Hatch/1.16.3 cpython/3.14.0 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6443fb8d20006e4f1e2c1011d62cd62716fd9758825b799a0546d94108411eb4
|
|
| MD5 |
040a351320bde934f014a78619c98497
|
|
| BLAKE2b-256 |
41153fbbc8a0f0c612975e2a01668c76f0cf9677e85db71d568488bbe224a7bc
|