Skip to main content

Over-Simple JSON RPC Implementation

Over-simple JSON-RPC Python implementation for aiohttp

Install

pip install osjsonrpc

Usage

Example:

from aiohttp import web
from osjsonrpc import JsonRpcEndpoint

def ping():
    return "pong"

def multiply(a, b):
    return {"a": a, "b": b, "a*b": a * b}

rpc = (
    JsonRpcEndpoint()
    .register_method(ping)
    .register_method(multiply)
)

app = web.Application()
app.add_routes([rpc.route("/api")])
web.run_app(app)

Call the ping method without arguments:

~ curl -s -H "Content-Type: application/json" -H "Accept: application/json" -X POST \
  -d '{"jsonrpc":"2.0", "method": "ping", "id": 1}' \
  http://localhost:8080/api | jq

{
  "jsonrpc": "2.0",
  "result": "pong",
  "id": 1
}

Call the multiply with a couple of positional arguments:

~ curl -s -H "Content-Type: application/json" -H "Accept: application/json" -X POST \
  -d '{"jsonrpc":"2.0", "method": "multiply", "params": [3, 5], "id": 1}' \
  http://localhost:8080/api | jq

{
  "jsonrpc": "2.0",
  "result": {
    "a": 3,
    "b": 5,
    "a*b": 15
  },
  "id": 1
}

Call the ping argument with invalid keyword argument:

~ curl -s -H "Content-Type: application/json" -H "Accept: application/json" -X POST \
  -d '{"jsonrpc":"2.0", "method": "ping", "params": {"key": "value"}, "id": 1}' \
  http://localhost:8080/api | jq

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32602,
    "message": "Invalid params",
    "data": {
      "detail": "TypeError: ping() got an unexpected keyword argument 'key'",
      "request": {
        "jsonrpc": "2.0",
        "method": "ping",
        "params": {
          "key": "value"
        },
        "id": 1
      }
    }
  },
  "id": 1
}

Metadata

Release files for osjsonrpc 0.2.3

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

Source distribution (sdist)

Source distribution for osjsonrpc 0.2.3
File Size Uploaded
osjsonrpc-0.2.3.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osjsonrpc 0.2.3
File Interpreter ABI Platform
osjsonrpc-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / osjsonrpc-0.2.3.tar.gz

Download URL osjsonrpc-0.2.3.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
39a20fac621bd5f7538d6baa40f8fb7c91863e2d4b0539aedb33430a85f0b96d
BLAKE2b-256 checksum
How to use checksums
770a85ad2e427f350a7e6cac8dc49cf23f2a5416c02fa9225628584ba737fdd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.3 CPython/3.6.9 Darwin/19.3.0

Release files / osjsonrpc-0.2.3-py3-none-any.whl

Download URL osjsonrpc-0.2.3-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df9397d09c57b072acd82988eb11b78495a55f09cf39ad35fb03f4d3c52bab3b
BLAKE2b-256 checksum
How to use checksums
ea405d7455d6b043b1ec1812e3cbd3d0e980d5f3e808ccf4c8abdaa54ca7fc4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.3 CPython/3.6.9 Darwin/19.3.0

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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