wsrpc-asgi
Bidirectional WebSocket RPC for asyncio ASGI applications. A fork of
wsrpc-aiohttp with an ASGI server
transport and an optional websockets Python client. Existing WSRPC Python
and JavaScript peers use the same wire protocol.
Supports functions, per-connection route objects, reverse calls, events, broadcast, lifecycle signals, custom JSON codecs and threaded handlers. The base package has no runtime dependencies. Python 3.10+ is supported.
Install
pip install 'wsrpc-asgi[fastapi,client]' uvicorn
For a local checkout use uv sync and uv run for the commands below.
FastAPI server
Save as app.py:
from fastapi import FastAPI, WebSocket
from wsrpc_asgi import WebSocketAsync
class RPC(WebSocketAsync):
pass
async def add(socket, *, a: int, b: int) -> int:
return a + b
RPC.add_route("add", add)
app = FastAPI()
@app.websocket("/ws/")
async def rpc(websocket: WebSocket):
await RPC.serve(websocket)
Run uvicorn app:app, then connect from Python:
import asyncio
from wsrpc_asgi import WSRPCClient
async def main():
async with WSRPCClient("ws://127.0.0.1:8000/ws/") as client:
print(await client.proxy.add(a=20, b=22))
if __name__ == "__main__":
asyncio.run(main())
Verify a round trip
This self-contained example runs the same RPC endpoint through FastAPI's in-process test client:
from fastapi import FastAPI, WebSocket
from fastapi.testclient import TestClient
from wsrpc_asgi import WebSocketAsync
class RPC(WebSocketAsync):
pass
RPC.add_route("add", lambda socket, a, b: a + b)
app = FastAPI()
@app.websocket("/ws/")
async def endpoint(websocket: WebSocket):
await RPC.serve(websocket)
with TestClient(app) as http:
with http.websocket_connect("/ws/") as socket:
socket.send_json(
{"id": 1, "method": "add", "params": {"a": 20, "b": 22}}
)
assert socket.receive_json() == {"id": 1, "result": 42}
Other ASGI frameworks
Use RPC.as_asgi() as a standalone ASGI application or framework route.
RPCMiddleware(http_app, rpc, path="/ws/") adds a WebSocket endpoint to an
existing ASGI application while forwarding its other traffic.
The framework guide includes runnable examples for FastAPI, Starlette, Django, Channels, Quart, Litestar, Falcon, Sanic, BlackSheep and bare ASGI, plus Uvicorn and Hypercorn commands. Each framework example is exercised over real HTTP and WebSocket connections.
The quick start includes a browser demo.
wsrpc_asgi.STATIC_DIR contains the unchanged JavaScript clients and
TypeScript declarations; they can also be obtained from @wsrpc/client.
Documentation and its runnable examples are maintained in wsrpc/docs.
Development
uv sync --locked
uv run --locked pytask
uv run --locked --group integrations pytest tests/test_examples.py
See development for the verification matrix, free-threaded Python and release workflow. Framework integration dependencies are test-only; applications install the framework they use.
Licensed under Apache-2.0. The bundled JavaScript client retains its MIT license. Upstream attribution and license notices are preserved.
Metadata
Release files for wsrpc-asgi 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wsrpc_asgi-0.2.0.tar.gz | 43.4 kB | With provenance | Details for wsrpc_asgi-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wsrpc_asgi-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for wsrpc_asgi-0.2.0-py3-none-any.whl |
Total release size: 83.0 kB
Release files / wsrpc_asgi-0.2.0.tar.gz
| Download URL | wsrpc_asgi-0.2.0.tar.gz |
|---|---|
| Size | 43.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0d3abff7f690b182f3907846652ed0b9a824d83fb8deffd0d0237466c203d67
|
|
BLAKE2b-256 checksum How to use checksums |
9fd8d138ff6ffe320b3b7f9ee11097555f0cafcb7b142c44b533b3096ba712df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / wsrpc_asgi-0.2.0-py3-none-any.whl
| Download URL | wsrpc_asgi-0.2.0-py3-none-any.whl |
|---|---|
| Size | 39.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
120e63731378e22139579618ab47256d61ed7c78254ac4047e2715d5a83f4a93
|
|
BLAKE2b-256 checksum How to use checksums |
1231baf30bcb5660b35b7122d192f2b5193ffdc8b5ae98a475313b61c5fdc933
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logSecurity for wsrpc-asgi 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for wsrpc_asgi-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.