from svc_infra.websocket.client import WebSocketClientAsync 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
async with WebSocketClient("wss://api.example.com") as ws: await ws.send_json({"type": "hello"}) async for message in ws: print(message)
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