Skip to main content

Simple JSON-RPC 2.0 client with no dependencies other than Python's standard library.

Project description

jrpc2

Simple JSON-RPC 2.0 client with no dependencies other than Python's standard library.

Requirements

Python 3.13+

Features

  • Support for JSON-RPC 1.0 and 2.0 (default)
  • HTTP transport
  • Basic HTTP auth
  • List params
  • Named params
  • Notifications
  • Batch support

Install

pip install jrpc2

Usage

from jrpc2 import RpcClient

url = 'http://user:pass@localhost:8332' # omit user:pass if there is no auth
rpc = RpcClient(url)

list_params = [1, 2]
named_params = {'a': 1, 'b': 2}

# Method calling with list or named params (one or the other, not both)
resp = rpc.call('testmethod') # no params
resp = rpc.call('testmethod2', 1, 2) # list params
resp = rpc.call('testmethod2', *list_params) # list params
resp = rpc.call('testmethod2', a=1, b=2) # named params
resp = rpc.call('testmethod2', **named_params) # named params

# Batch calling
resp = rpc.batch(['testmethod', 'testmethod2'], [[], [1, 2]])
resp = rpc.batch(['testmethod2', 'testmethod2'], [{'a': 5, 'b': 3}, {'a': 2, 'b': 1}])
resp = rpc.batch(['testmethod3', 'testmethod4']) # no params

# Notification
rpc.notify('testmethod5', 'test_data')
rpc.notify('testmethod5', test_data='test_data')
rpc.batch(['testmethod5', 'testmethod5'], [['test_data'], ['test_data2']], _notify=True)

The response is a dictionary of the JSON response object returned from the server (even on errors). An exception is raised if there is an error at the HTTP level when making the call/request.

The RPC 'id' is handled internally and incremented by 1 on each request.

RPC methods can also be called directly as attributes, provided that a method list is passed when creating the client:

rpc = RpcClient(url, methods=['testmethod', 'testmethod2'])

resp = rpc.testmethod() # no params
resp = rpc.testmethod2(1, 2) # list params
resp = rpc.testmethod2(a=1, b=2) # named params

CLI

A CLI script (rpc-cli) is included for quick tests.

rpc-cli [-h] [-v] url method [params ...]
rpc-cli http://user:pass@localhost:8332 testmethod
rpc-cli http://user:pass@localhost:8332 testmethod2 1 2
rpc-cli http://user:pass@localhost:8332 testmethod2 a=1 b=2

License

Distributed under the MIT License. See the accompanying file 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

jrpc2-2026.5.10.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

jrpc2-2026.5.10-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file jrpc2-2026.5.10.tar.gz.

File metadata

  • Download URL: jrpc2-2026.5.10.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for jrpc2-2026.5.10.tar.gz
Algorithm Hash digest
SHA256 5063d18c6503fad0a1fe2f74ab8925fe772132c41d43adc64416ac64ddecef78
MD5 74911645a6d6cc90487c8a0282eb170e
BLAKE2b-256 8d2af048e40886a3953df1d2a432b1853f8cad6dd97f0d8bbca5bbbec9586edb

See more details on using hashes here.

File details

Details for the file jrpc2-2026.5.10-py3-none-any.whl.

File metadata

  • Download URL: jrpc2-2026.5.10-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for jrpc2-2026.5.10-py3-none-any.whl
Algorithm Hash digest
SHA256 08fc8116b40e1a56745232b0b08b182ba59f4609c8ee7b7bdd96a3a57da44095
MD5 888ec3d33cbd155e8ea2c51fa4c7f6ad
BLAKE2b-256 eaa68b3663ddeceb67f4179665313afa6ed5cd70ddd88c532c8410e1fc3eb888

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