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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jrpc2-2026.4.7.tar.gz
Algorithm Hash digest
SHA256 e10f8bbee833076c4f5e328161cefb4d7ce07eabec552f1cdb35407abf2fd715
MD5 28f21f01510efed9f8e6618b0817a155
BLAKE2b-256 9bd6a5a41d1948d0c354fddbaed6fe76d82ce9caff17ae3281c0e57547124f85

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jrpc2-2026.4.7-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.11

File hashes

Hashes for jrpc2-2026.4.7-py3-none-any.whl
Algorithm Hash digest
SHA256 657519bbb6e3b5cd91bcc850ec553a6876349b6081d568b7615809c596b37856
MD5 f4a05445a9ef68acbb14ee6818eb60ea
BLAKE2b-256 ad9990b95dd79beb1b0fbf3e1e66603c8c98a17e87acd30b77fd5e08a8e260b7

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