Skip to main content

Bidirectional JSON-RPC 2.0 over WebSocket — TypeScript & Python.

Project description

EchoRPC

Bidirectional JSON-RPC 2.0 over WebSocket for Python.

Install

pip install echorpc

Quick Start

Server

from echorpc import EchoServer

server = EchoServer(port=9100, auth_handler=lambda p: p["token"] == "secret")

# Define a command that clients can call
@server.command("add")
def add(params):
    return {"sum": params["a"] + params["b"]}

# Listen for events from clients
@server.event("chat")
async def on_chat(data):
    print("on_chat", data)

await server.start()

Client

from echorpc import EchoClient

client = EchoClient("ws://localhost:9100", token="secret")

# Let the server call you back
client.register("double", lambda p: p["x"] * 2)

# Subscribe to events
client.subscribe("chat", lambda data: print(data))

await client.connect()

# Call a server command
result = await client.request("add", {"a": 1, "b": 2})

# Publish event to the server
await client.publish("chat", {"text": "hello"})

# Send multiple calls at once
results = await client.batch_request([
    ("add", {"a": 1, "b": 2}),
    ("add", {"a": 3, "b": 4}),
])

Error Codes

Code Name Meaning
-32700 Parse error Invalid JSON
-32601 Method not found No such method
-32603 Internal error Handler threw
-32001 Not connected No active connection
-32002 Timeout Request timed out
-32003 Auth failed Authentication rejected

License

MIT License © 2026-PRESENT Del Wang

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

echorpc-1.0.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

echorpc-1.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file echorpc-1.0.0.tar.gz.

File metadata

  • Download URL: echorpc-1.0.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for echorpc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bc82970be25848d2bdc75fc5606c369b643a4186365c56f04fb93d772bfb4e41
MD5 042376e4b95f85063def6e84fa0dabbb
BLAKE2b-256 296fab37fb406aa8902b1a41354b683b88b15fc811e7869168f0b40a604d5a92

See more details on using hashes here.

File details

Details for the file echorpc-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: echorpc-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for echorpc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a5d71b11fd22958c131e1ccd56d653c198b04fbd95f234688baec3a6f2b1de3
MD5 c5a37f8310dbf81fdc3824d50d6644a9
BLAKE2b-256 af93ff090a44e6627b1cd6337845753202ec0065dc018d4a45953b85d6aff8fe

See more details on using hashes here.

Supported by

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