Skip to main content

jsonrpc-async: a compact JSON-RPC client library for asyncio

https://img.shields.io/pypi/v/jsonrpc-async.svg https://github.com/emlove/jsonrpc-async/workflows/tests/badge.svg https://coveralls.io/repos/emlove/jsonrpc-async/badge.svg

This is a compact and simple JSON-RPC client implementation for asyncio python code. This code is forked from https://github.com/gciotta/jsonrpc-requests

Main Features

  • Supports nested namespaces (eg. app.users.getUsers())

  • 100% test coverage

Usage

It is recommended to manage the aiohttp ClientSession object externally and pass it to the Server constructor. (See the aiohttp documentation.) If not passed to Server, a ClientSession object will be created automatically.

Execute remote JSON-RPC functions

import asyncio
from jsonrpc_async import Server

async def routine():
    async with Server('http://localhost:8080') as server:
        await server.foo(1, 2)
        await server.foo(bar=1, baz=2)
        await server.foo({'foo': 'bar'})
        await server.foo.bar(baz=1, qux=2)

asyncio.get_event_loop().run_until_complete(routine())

A notification

import asyncio
from jsonrpc_async import Server

async def routine():
    async with Server('http://localhost:8080') as server:
        await server.foo(bar=1, _notification=True)

asyncio.get_event_loop().run_until_complete(routine())

Pass through arguments to aiohttp (see also aiohttp documentation)

import asyncio
import aiohttp
from jsonrpc_async import Server

async def routine():
    async with Server(
        'http://localhost:8080',
        auth=aiohttp.BasicAuth('user', 'pass'),
        headers={'x-test2': 'true'}
    ) as server:
        await server.foo()

asyncio.get_event_loop().run_until_complete(routine())

Pass through aiohttp exceptions

import asyncio
import aiohttp
from jsonrpc_async import Server

async def routine():
    async with Server('http://unknown-host') as server:
        try:
            await server.foo()
        except TransportError as transport_error:
            print(transport_error.args[1]) # this will hold a aiohttp exception instance

asyncio.get_event_loop().run_until_complete(routine())

Tests

Install the Python tox package and run tox, it’ll test this package with various versions of Python.

Changelog

2.2.0 (2026-11-19)

  • Wrap errors of reading the reply in TransportError (#12) @olympia

2.1.3 (2025-08-21)

2.1.2 (2023-07-10)

2.1.1 (2022-05-03)

  • Unpin test dependencies

2.1.0 (2021-05-03)

  • Bumped jsonrpc-base to version 2.1.0

2.0.0 (2021-03-16)

  • Bumped jsonrpc-base to version 2.0.0

  • BREAKING CHANGE: Allow single mapping as a positional parameter. Previously, when calling with a single dict as a parameter (example: server.foo({'bar': 0})), the mapping was used as the JSON-RPC keyword parameters. This made it impossible to send a mapping as the first and only positional parameter. If you depended on the old behavior, you can recreate it by spreading the mapping as your method’s kwargs. (example: server.foo(**{'bar': 0}))

1.1.1 (2019-11-12)

  • Bumped jsonrpc-base to version 1.0.3

1.1.0 (2018-09-04)

  • Added support for using a custom json.loads method (#1) @tdivis

1.0.1 (2018-08-23)

  • Bumped jsonrpc-base to version 1.0.2

1.0.0 (2018-07-06)

  • Bumped minimum aiohttp version to 3.0.0

  • Bumped jsonrpc-base to version 1.0.1

Credits

@gciotta for creating the base project jsonrpc-requests.

@mbroadst for providing full support for nested method calls, JSON-RPC RFC compliance and other improvements.

@vaab for providing api and tests improvements, better RFC compliance.

Metadata

Release files for jsonrpc-async 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonrpc-async 2.2.0
File Size Uploaded Provenance Actions
jsonrpc_async-2.2.0.tar.gz 5.2 kB Without provenance Details for jsonrpc_async-2.2.0.tar.gz

Release files / jsonrpc_async-2.2.0.tar.gz

Download URL jsonrpc_async-2.2.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
af803ec0daf560fe708988054198a35394ffca50ab8656c0b71da4a7ddbeb3e5
BLAKE2b-256 checksum
How to use checksums
e2cd7b192e53da577055feda6afe6990ccf3fd19a71e502921f5a1a83b968784
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for jsonrpc-async 2.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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