Skip to main content

Fast utilities for working with JSON-RPC 2.0 messages

Project description

FastJSON-RPC2

Typed utilities for working with JSON-RPC 2.0 messages. FastJSON-RPC2 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-rpc2

For local development:

python3 -m venv .venv
source .venv/bin/activate
pip install -e .[dev]

Usage

from fastjson_rpc2 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,
)

print(error_response.error.human_readable_code()) # -> 'METHOD_NOT_FOUND'

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

fastjson_rpc2-1.0.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastjson_rpc2-1.0.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file fastjson_rpc2-1.0.0.tar.gz.

File metadata

  • Download URL: fastjson_rpc2-1.0.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

Hashes for fastjson_rpc2-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8733fd4fcc4fdd07947a20585c6dd0a8f885c649fcf7ca41f0f8a92c30a4ad0a
MD5 38463bfe2ea21e4cf89d10fab352d611
BLAKE2b-256 8e6aa61e0d6826e9580220d8cf7d2a2589515477e02c4d43012f4261b51931ae

See more details on using hashes here.

File details

Details for the file fastjson_rpc2-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: fastjson_rpc2-1.0.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

Hashes for fastjson_rpc2-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2adbdd194dcd5695c4ad534a4090e2f72f63243f1b84b2ea1f0bc0287529c52c
MD5 3ebf162f457fa63093a3117a91113477
BLAKE2b-256 898979a2043e49eac4278bc941865e6372a37f328409bb069d775647e102033e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page