Skip to main content

Framework-agnostic Python JSON-RPC 2.0 toolkit with Safe Mode interoperability.

Project description

RPC Python Toolkit

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

Small early 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)

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)

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

Related Projects

License

MIT. See LICENSE.

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

rpc_python_toolkit-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

rpc_python_toolkit-0.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file rpc_python_toolkit-0.1.0.tar.gz.

File metadata

  • Download URL: rpc_python_toolkit-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rpc_python_toolkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 537b05f3fb0257fed99a20edfa0b29263769bba582c9ef180c199757b91b198a
MD5 c76abb018c6bc7c623ca977fe05697ad
BLAKE2b-256 f8131cc809cb32159e59ef974e9636922d86889f203271dc2d40b90bd4066ce8

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpc_python_toolkit-0.1.0.tar.gz:

Publisher: publish-pypi.yml on n-car/rpc-python-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rpc_python_toolkit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rpc_python_toolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de90172f1d713f40eca40adc5c447b8b0d47d86e47e6ebbc8e60d5b107c0c6b6
MD5 9e1bdd6498ea87f38a8865fe284679d5
BLAKE2b-256 aca7d20cdaab10b406e8ff5bc1c980d979d065a22c5a262f4fd81507df85c6d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpc_python_toolkit-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on n-car/rpc-python-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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