Skip to main content

RPC Python Toolkit

CI PyPI Version Python Versions License Status

Framework-agnostic JSON-RPC 2.0 toolkit for Python.

Use this package when you need a small Python JSON-RPC 2.0 client/server core that can be embedded directly or adapted to HTTP frameworks. It follows the same protocol conventions used across the RPC Toolkit ecosystem.

Project Status

Alpha package with the core JSON-RPC behavior implemented.

  • Published on PyPI as rpc-python-toolkit.
  • Standard JSON-RPC 2.0 remains the default behavior.
  • Safe Mode follows the same X-RPC-Safe-Enabled and value marker conventions used by rpc-express-toolkit.
  • The public API may still change before a stable Python release.

Installation

Install from PyPI:

pip install rpc-python-toolkit

For development snapshots, install from GitHub or from a local checkout:

pip install git+https://github.com/n-car/rpc-python-toolkit.git

For local development:

pip install -e .
python -m unittest discover

What Is Implemented

  • Framework-independent RpcEndpoint
  • Standard JSON-RPC calls, notifications, and batch requests
  • RpcClient and RpcSafeClient over HTTP using Python standard library
  • JSON Schema validation through jsonschema
  • Optional RPC Toolkit Safe Mode over HTTP headers
  • Method introspection with __rpc.* methods

What Is Not Implemented Yet

  • Built-in ASGI/WSGI adapters for FastAPI, Starlette, Flask, or Django
  • Async endpoint handlers
  • OpenRPC export
  • Built-in HTTP server adapters

Quick Start

from rpc_python_toolkit import RpcEndpoint

rpc = RpcEndpoint(
    enable_introspection=True,
    enable_batch=True,
    max_batch_size=100,
)

def test(request, context, params):
    return {"ok": True, "params": params}

rpc.add_method("test", test)

response = rpc.handle_payload({
    "jsonrpc": "2.0",
    "method": "test",
    "params": {"value": 123},
    "id": 1,
})

print(response.body)

Batch can be disabled with enable_batch=False. Introspection remains opt-in. When both application and request contexts are dictionaries, handlers receive a merged dictionary and request values take precedence. For a non-dictionary application context plus request data, handlers receive RpcCallContext with separate application and request attributes.

Result:

{"jsonrpc": "2.0", "id": 1, "result": {"ok": true, "params": {"value": 123}}}

HTTP Client

from rpc_python_toolkit import RpcClient

client = RpcClient("http://localhost:3000/api")
result = client.call("test", {"value": 123})

Safe Mode

Use RpcSafeEndpoint and RpcSafeClient when both sides support RPC Toolkit Safe Mode:

from rpc_python_toolkit import RpcSafeEndpoint, RpcSafeClient

rpc = RpcSafeEndpoint()
client = RpcSafeClient("http://localhost:3000/api")

Safe Mode enables X-RPC-Safe-Enabled negotiation and recursive value encoding/decoding:

  • strings are encoded as S:<value>
  • datetimes are encoded as D:<iso-date>
  • large integers are encoded as <digits>n

Python exposes arbitrary precision integers as int. BigInt marker strings from other RPC Toolkit implementations are decoded to Python int values when they are real markers, while literal marker-like strings are protected by the S: prefix in Safe Mode.

Examples

Runnable examples are available in examples/:

  • basic_server.py - direct endpoint usage without an HTTP adapter.
  • basic_client.py - standard HTTP client call against an in-process endpoint.
  • schema_validation.py - method schema validation and JSON-RPC error output.
  • safe_mode.py - RpcSafeClient to RpcSafeEndpoint round-trip for strings, dates, and large integers.

For local checkout usage:

PYTHONPATH=src python3 examples/basic_server.py
PYTHONPATH=src python3 examples/basic_client.py
PYTHONPATH=src python3 examples/schema_validation.py
PYTHONPATH=src python3 examples/safe_mode.py

License

MIT. See LICENSE.

Metadata

Release files for rpc-python-toolkit 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rpc-python-toolkit 0.2.0
File Size Uploaded
rpc_python_toolkit-0.2.0.tar.gz 14.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rpc-python-toolkit 0.2.0
File Interpreter ABI Platform
rpc_python_toolkit-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.8 kB

Release files / rpc_python_toolkit-0.2.0.tar.gz

Download URL rpc_python_toolkit-0.2.0.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
81391fcbdf2346474eaca1d73fc3a6edd2c8f8f39fc866eec6d2854045bd4cc7
BLAKE2b-256 checksum
How to use checksums
6c6d04e98110a50b713bcca6b73259cd37b1c4d6753eceeeb231ea0c17255034
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / rpc_python_toolkit-0.2.0-py3-none-any.whl

Download URL rpc_python_toolkit-0.2.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87ba155d39aa1cda807785d6a1ef392a8bb9bb97b61bbc722e140ef999c25357
BLAKE2b-256 checksum
How to use checksums
f872ba4bcee4bfcfc9aa999ab131196fa29c376644712583b52259bf64193171
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page