This post uses Jsonrpcserver 5 which requires Python 3.8+.

zeromq json

We’ll use ZeroMQ to take JSON-RPC requests. It should respond to “ping” with “pong”.

Install pyzmq to take requests and jsonrpcserver to process them:

pip install pyzmq jsonrpcserver

Create a

from jsonrpcserver import method, Result, Success, dispatch
import zmq

socket = zmq.Context().socket(zmq.REP)

def ping() -> Result:
    return Success("pong")

if __name__ == "__main__":
    while True:
        request = socket.recv().decode()

Start the server:

$ python ./


Use jsonrpcclient to send requests:

pip install pyzmq jsonrpcclient
>>> from jsonrpcclient import request_json, parse_json, Ok
>>> import zmq
>>> socket = zmq.Context().socket(zmq.REQ)
>>> socket.connect("tcp://localhost:5000")
>>> socket.send_string(request_json("ping"))
>>> response = parse_json(socket.recv().decode())
>>> response.result