🎉 svc-infra v1.0 is here — Production-ready backend infrastructure
What's new
nfrax logonfrax

Infrastructure that just works. Ship products, not boilerplate.

Frameworks

  • svc-infra
  • ai-infra
  • fin-infra
  • robo-infra

Resources

  • Getting Started
  • What's New
  • Contributing

Community

  • GitHub

© 2026 nfrax. All rights reserved.

nfrax logonfrax
Start HereWhat's New
GitHub
svc-infra / API Reference

WebSocketClient

from svc_infra.websocket.client import WebSocketClient
svc_infra.websocket.client

Async WebSocket client for connecting to external services. Features: - Async context manager support - Auto-reconnection with exponential backoff (via websocket_connect) - Configurable ping/pong keepalive - Send text, bytes, or JSON - Async iterator for receiving messages

Example

async with WebSocketClient("wss://api.example.com") as ws: await ws.send_json({"type": "hello"}) async for message in ws: print(message)

Args

url: WebSocket URL (ws:// or wss://) config: WebSocket configuration (timeouts, ping/pong, etc.) headers: Additional HTTP headers for the handshake subprotocols: List of subprotocols to negotiate

Constructor
WebSocketClient(url: str, config: WebSocketConfig | None = None, headers: dict[str, str] | None = None, subprotocols: list[str] | None = None)
ParameterTypeDefaultDescription
urlrequiredstr——
configWebSocketConfig |NoneNone—
headersdict[str, str] |NoneNone—
subprotocolslist[str] |NoneNone—

Methods

On This Page

Constructorcloseconnectrecvrecv_jsonsendsend_json