Transports¶
jsonrpcclient only builds requests and parses responses, so you pair it with a
library that sends them. Each page below has a complete example that talks to
a JSON-RPC server on localhost:8000 that answers ping with pong. CI runs
every one of them against a test server.
| Library | Transport | Sync or async |
|---|---|---|
| urllib (standard library) | HTTP | sync |
| requests | HTTP | sync |
| httpx | HTTP | both |
| aiohttp | HTTP | async |
| websockets | WebSocket | async |
| pyzmq | ZeroMQ | sync |
The pattern is the same everywhere:
- Build the request with
request(orrequest_jsonif the library sends text). - Send it, and check for transport errors such as an HTTP error status.
- Parse the reply with
parse(orparse_jsonfor text), then check whether you got anOkor anError.
Error handling lists what can go wrong at each step.
Port 8000
The examples use port 8000. Port 5000, which many tutorials use, is taken by the AirPlay Receiver on recent macOS versions.