Skip to main content

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-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-0.1.2.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-0.1.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastjson_rpc2-0.1.2.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-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ff73b7a787fb72785ddf4d1deebb868774ae1342ddc0ef3e717eb85cef5e0ab9
MD5 87235584b33a68d511923f65693b625c
BLAKE2b-256 ed68e5c64b08e447e48889d60c38397b0d997619652466526515421746a1cd53

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastjson_rpc2-0.1.2-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-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b114f8a02f53197967592c35ce92cc15e99af57a9560737d92c9117bdfde306
MD5 128327623689d4223702ca3d7e19152e
BLAKE2b-256 4f78db2d9227582e53b6de96791f684f065929719315d0c54c510318ccba9b78

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