Skip to main content

jrpc-core

PyPI - Version PyPI - Python Version Tests Coverage Status


A lightweight, type-safe Python implementation of the JSON-RPC 2.0 specification.

jrpc-core provides two core layers:

Layer Module Purpose
Messages jrpc_core.messages Pydantic models for requests, responses, notifications, and errors
Dispatcher jrpc_core.dispatcher Async registry-based routing of incoming messages to handler callables

Table of Contents

Features

  • Type-safe — every model is a Pydantic BaseModel with explicit field types and validators.
  • Functional — error handling uses Result and Option from pyfplib instead of exceptions.
  • Lightweight — only depends on pydantic and pyfplib, no async runtime required.
  • Serialisable — round-trips cleanly between Python objects and JSON strings.
  • Extensible — custom response constructors, parameter validators, and converters.

Quick Start

import asyncio
from jrpc_core import JsonRpcRequest, JsonRpcDispatcher, JsonRpcMethodWrapper

# Create a request
request = JsonRpcRequest(method="add", params=[1, 2])
print(request.to_json())
# {"jsonrpc":"2.0","method":"add","params":[1,2],"id":"<uuid>"}

# Parse incoming JSON-RPC message
from jrpc_core import try_parse
result = try_parse('{"jsonrpc":"2.0","method":"add","params":[1,2],"id":"1"}')

# Use the dispatcher
async def main():
    dispatcher = JsonRpcDispatcher()
    dispatcher.request_handler_registry.add(
        JsonRpcMethodWrapper(name="add", method=lambda args: args[0] + args[1])
    )
    response = await dispatcher(JsonRpcRequest(method="add", params=[1, 2], id=1))
    print(response.unwrap().unwrap().result)  # 3

asyncio.run(main())

Documentation

Documentation pages.

Installation

pip install jrpc-core

License

jrpc-core is distributed under the terms of the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jrpc_core-0.2.0.tar.gz (638.3 kB view details)

Uploaded Source

Built Distribution

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

jrpc_core-0.2.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file jrpc_core-0.2.0.tar.gz.

File metadata

  • Download URL: jrpc_core-0.2.0.tar.gz
  • Upload date:
  • Size: 638.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.14.0 HTTPX/0.28.1

File hashes

Hashes for jrpc_core-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2a7febc5f48cf28f5e716fb6c43273bf9fb8c9eda47cd3cc3cba4b66b59ae7f6
MD5 d88ce1b169b09bfc8beee911764961cf
BLAKE2b-256 553843abcb78925912e9dee1365c0dd6af9f2ce03efe86ddddd83cce8f64c583

See more details on using hashes here.

File details

Details for the file jrpc_core-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jrpc_core-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.14.0 HTTPX/0.28.1

File hashes

Hashes for jrpc_core-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48b694dfe5fd943f00e45345accecd8d2bf33063262b81825b4aa828f5707431
MD5 7341307b98f11eea33dff8a5f1878e62
BLAKE2b-256 20ae149955089dc31adcdce49f77e29185018f72abc00165349c4f1b0c56e8c0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.1

2 files

0.1.0

2 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