Skip to main content

Protocol-agnostic asynchronous Python JSON-RPC module

Project description

asyncjsonrpc

An asynchronous JSON-RPC client/server for Python. Currently supports WebSocket transports, though more may be added in the future.

Module documentation asyncjsonrpc on PyPi

Install

Install from PyPi via pip:

pip3 install asyncjsonrpc

Features

  • Compliant with the JSON-RPC 2.0 specification
  • Transport-agnostic design, could potentially work with any network protocol supported by Python and asyncio
  • JSON-RPC over WebSockets support via aiohttp

Unimplemented JSON-RPC Features

  • Batched requests
  • Manifests

Examples

See the examples directory for more.

Quick server example

import asyncjsonrpc
from aiohttp import web

methods = asyncjsonrpc.MethodGroup()

@methods.method
def greet(name):
    return f'Hello {name}!'

rpcserver = asyncjsonrpc.server.AiohttpWebsocketServer(methods)
app = web.Application()
app.add_routes([web.get('/', rpcserver)])
web.run_app(app)

Quick client example

import asyncjsonrpc, asyncio
from aiohttp import web

async def main():
    client = asyncjsonrpc.client.AiohttpWebsocketClient()
    await client.connect('http://localhost:8080/')
    print(await client.greet('world'))

asyncio.run(main())

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

asyncjsonrpc-1.0.0.tar.gz (14.0 kB view hashes)

Uploaded Source

Built Distribution

asyncjsonrpc-1.0.0-py3-none-any.whl (19.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page