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

Copyright (C) 2026 by Joel Torres <joel@joeltorres.net>

Distributed under the Zero-Clause BSD license. See the accompanying file LICENSE or https://opensource.org/license/0bsd.

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.3.8.tar.gz (4.2 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.3.8-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jrpc2-2026.3.8.tar.gz
Algorithm Hash digest
SHA256 8142323ac4180b96bdc053ce4ad4b179fa0239dab235f2493379342aaee43f99
MD5 94f8b4a3130c2197e23a5b7f79fa631f
BLAKE2b-256 d138c9e9460f94e23ee5c748ce0e8d8f5889565b6fbe2ed8100fca22d087db3a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jrpc2-2026.3.8-py3-none-any.whl
  • Upload date:
  • Size: 5.4 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.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9a081c49273cee05d608b1ba193979df814d3a8271e5f0d4144f7b8448c56b5a
MD5 6cb38edebe3de13b3c29c18ec342f71f
BLAKE2b-256 ddd3bd05d3598843e0e03a940862b17bfff6ed489f71b382ae676f1eae3f2a98

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