Skip to content

API Reference

chumicro_websockets

Non-blocking WebSocket client and server for CircuitPython, MicroPython, and CPython.

The public entry points are :class:WebSocketClient and :class:WebSocketServer.

WebSocketBackpressureError

Bases: WebSocketError

The TX queue overflowed before the runner could drain it.

WebSocketError

Bases: Exception

Base class for every chumicro-websockets failure.

WebSocketHandshakeError

Bases: WebSocketError

The opening handshake failed (bad status, headers, or HTTP framing).

WebSocketProtocolError

Bases: WebSocketError

Peer sent bytes that RFC 6455 requires closing the connection on.

WebSocketState

Lifecycle states for a websocket session.

WebSocketStateError

Bases: WebSocketError

Caller invoked an operation that requires a different session state.

WebSocketTimeoutError

Bases: WebSocketError

A per-phase timeout elapsed (handshake, close, or pong-after-ping).

WebSocketURLError

Bases: WebSocketError

URL doesn't parse as a supported ws:// / wss:// URL.

InboundMessage

A complete inbound WebSocket data message returned by next_message.

WhenOversized

Policy for inbound messages exceeding max_message_bytes.

derive_accept_key(client_key)

Compute Sec-WebSocket-Accept from the client's nonce.

Parameters:

Name Type Description Default
client_key str

Verbatim base64 nonce; do not decode it first.

required

make_websocket_key()

Generate a fresh Sec-WebSocket-Key (16 random bytes, base64 ASCII) per RFC 6455 §4.1.

parse_ws_url(url)

Split a ws:// or wss:// url into (scheme, host, port, path).

Raises:

Type Description
WebSocketURLError

Bad scheme, missing host, or out-of-range port.