Fast utilities for working with JSON-RPC 2.0 messages
Project description
FastJSON-RPC
Typed utilities for working with JSON-RPC 2.0 messages. FastJSON-RPC ships strictly-typed Pydantic models for requests and responses, helpers for working with sentinel values, and human-readable error codes for debugging.
Features
- JSON-RPC 2.0 request/response models with built-in validation.
- Helper types (
UnsetType,JsonRpcId,ErrorObject) re-exported via the package root for convenience. - Boolean helpers (
is_notification,is_error) that express protocol semantics.
Installation
pip install fastjson-rpc
For local development:
python3 -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
Usage
from fastjson_rpc import JsonRpcRequest, JsonRpcResponse, ErrorObject
# Build a notification request
request = JsonRpcRequest(jsonrpc="2.0", method="ping", params={"foo": "bar"})
assert request.is_notification()
# Build a response with either result or error
response = JsonRpcResponse(jsonrpc="2.0", result={"pong": True}, id=1)
if response.is_error():
handle_error(response.error)
else:
handle_result(response.result)
# Create an error response
error_response = JsonRpcResponse(
jsonrpc="2.0",
error=ErrorObject(code=-32601, message="Method not found"),
id=1,
)
Testing
pytest
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file fastjson_rpc2-0.1.0.tar.gz.
File metadata
- Download URL: fastjson_rpc2-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2111bdf54d3897be005bbe84511e5655613663eb691cbeb19d24fe9b1048ede
|
|
| MD5 |
ef71fd6f1fd70e91c546e7459815d9c9
|
|
| BLAKE2b-256 |
30db4cfff41b09f0f8307b8a54109a563d2f1b6598adac5526160d01a0ff69a0
|
File details
Details for the file fastjson_rpc2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastjson_rpc2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55170520427353c7a17f5e99ba7b1abcb9dae4d8b704f3bfa34c5aa937973ccd
|
|
| MD5 |
4dde7c41464839a3a042c4561ce761d3
|
|
| BLAKE2b-256 |
a1decd930eeb84c3b35210682285995b9feb4f87d36cead275c7259eb48ac1ae
|