websockets API reference
246 public APIs from websockets (python-websockets/websockets) — 55 classes, 45 functions, 146 methods. Signatures extracted by static analysis of the actual source.
Repository: python-websockets/websockets
| Kind | Count |
|---|---|
| Classes | 55 |
| Functions | 45 |
| Methods | 146 |
API list
class
experiments.json_log_formatter.JSONFormatterRender logs as JSON.
method
src.websockets.asyncio.client.ClientConnection.handshake(additional_headers:HeadersLike | None=None, user_agent_header:str | None=USER_AGENT) -> NonePerform the opening handshake.
method
src.websockets.asyncio.client.ClientConnection.process_event(event:Event) -> NoneProcess one incoming event.
class
src.websockets.asyncio.client.connectConnect to the WebSocket server at ``uri``.
method
src.websockets.asyncio.connection.Connection.acknowledge_pings(data:bytes) -> NoneAcknowledge pings when receiving a pong.
method
src.websockets.asyncio.connection.Connection.close(code:CloseCode | int=CloseCode.NORMAL_CLOSURE, reason:str='') -> NonePerform the closing handshake.
method
src.websockets.asyncio.connection.Connection.local_address() -> AnyLocal address of the connection.
method
src.websockets.asyncio.connection.Connection.ping(data:DataLike | None=None) -> Awaitable[float]Send a Ping_.
method
src.websockets.asyncio.connection.Connection.pong(data:DataLike=b'') -> NoneSend a Pong_.
method
src.websockets.asyncio.connection.Connection.process_event(event:Event) -> NoneProcess one incoming event.
method
src.websockets.asyncio.connection.Connection.remote_address() -> AnyRemote address of the connection.
method
src.websockets.asyncio.connection.Connection.send(message:DataLike | Iterable[DataLike] | AsyncIterable[DataLike], *text:bool | None=None) -> NoneSend a message.
method
src.websockets.asyncio.connection.Connection.send_data() -> NoneSend outgoing data.
method
src.websockets.asyncio.connection.Connection.set_recv_exc(exc:BaseException | None) -> NoneSet recv_exc, if not set yet.
method
src.websockets.asyncio.connection.Connection.wait_closed() -> NoneWait until the connection is closed.
class
src.websockets.asyncio.messages.AssemblerAssemble messages from frames.
method
src.websockets.asyncio.messages.Assembler.close() -> NoneEnd the stream of frames.
method
src.websockets.asyncio.messages.Assembler.put(frame:Frame) -> NoneAdd ``frame`` to the next message.
class
src.websockets.asyncio.messages.SimpleQueueSimplified version of :class:`asyncio.Queue`.
method
src.websockets.asyncio.messages.SimpleQueue.abort() -> NoneClose the queue, raising EOFError in get() if necessary.
method
src.websockets.asyncio.messages.SimpleQueue.get(block:bool=True) -> TRemove and return an item from the queue, waiting if necessary.
method
src.websockets.asyncio.messages.SimpleQueue.put(item:T) -> NonePut an item into the queue.
method
src.websockets.asyncio.messages.SimpleQueue.reset(items:Iterable[T]) -> NonePut back items into an empty, idle queue.
class
src.websockets.asyncio.router.RouterWebSocket router supporting :func:`route`.
method
src.websockets.asyncio.router.Router.handler(connection:ServerConnection) -> NoneHandle a connection.
method
src.websockets.asyncio.router.Router.route_request(connection:ServerConnection, request:Request) -> Response | NoneRoute incoming request.
class
src.websockets.asyncio.server.ServerWebSocket server returned by :func:`serve`.
method
src.websockets.asyncio.server.Server.close(close_connections:bool=True, code:CloseCode | int=CloseCode.GOING_AWAY, reason:str='') -> NoneClose the server.
method
src.websockets.asyncio.server.Server.connections() -> set[ServerConnection]Set of active connections.
method
src.websockets.asyncio.server.Server.get_loop() -> asyncio.AbstractEventLoopSee :meth:`asyncio.Server.get_loop`.
method
src.websockets.asyncio.server.Server.is_serving() -> boolSee :meth:`asyncio.Server.is_serving`.
method
src.websockets.asyncio.server.Server.serve_forever() -> NoneSee :meth:`asyncio.Server.serve_forever`.
method
src.websockets.asyncio.server.Server.sockets() -> tuple[socket.socket, ...]See :attr:`asyncio.Server.sockets`.
method
src.websockets.asyncio.server.Server.start_serving() -> NoneSee :meth:`asyncio.Server.start_serving`.
method
src.websockets.asyncio.server.Server.wait_closed() -> NoneWait until the server is closed.
func
src.websockets.asyncio.server.process_request(connection:ServerConnection, request:Request) -> Response | NonePerform HTTP Basic Authentication.
func
src.websockets.asyncio.server.protocol_handler(connection:ServerConnection) -> NoneHandle the lifecycle of a WebSocket connection.
func
src.websockets.cli.escape(string:str) -> strMake a string safe for a terminal by escaping control characters.
class
src.websockets.client.ClientProtocolSans-I/O implementation of a WebSocket client connection.
method
src.websockets.client.ClientProtocol.connect() -> RequestCreate a handshake request to open a connection.
method
src.websockets.client.ClientProtocol.process_response(response:Response) -> NoneCheck a handshake response.
method
src.websockets.client.ClientProtocol.send_request(request:Request) -> NoneSend a handshake request to the server.
class
src.websockets.datastructures.HeadersEfficient data structure for manipulating HTTP headers.
method
src.websockets.datastructures.Headers.clear() -> NoneRemove all headers.
method
src.websockets.datastructures.Headers.get_all(key:str) -> list[str]Return the (possibly empty) list of all values for a header.
method
src.websockets.datastructures.Headers.set_insecure(key:str, value:str) -> NoneSet a header without validating its value.
method
src.websockets.datastructures.Headers.update(*args:HeadersLike, **kwargs:str) -> NoneUpdate from a :class:`Headers` instance and/or keyword arguments.
class
src.websockets.exceptions.ConcurrencyErrorRaised when receiving or sending messages concurrently.
class
src.websockets.exceptions.InvalidHandshakeBase class for exceptions raised when the opening handshake fails.
class
src.websockets.exceptions.InvalidHeaderRaised when an HTTP header doesn't have a valid format or value.
class
src.websockets.exceptions.InvalidHeaderFormatRaised when an HTTP header cannot be parsed.
class
src.websockets.exceptions.InvalidHeaderValueRaised when an HTTP header has a wrong value.
class
src.websockets.exceptions.InvalidMethodRaised when a handshake request doesn't use HTTP GET.
class
src.websockets.exceptions.InvalidOriginRaised when the Origin header in a request isn't allowed.
class
src.websockets.exceptions.InvalidProtocolRaised when a handshake request doesn't use HTTP/1.1.
class
src.websockets.exceptions.InvalidProxyRaised when connecting via a proxy that isn't valid.
class
src.websockets.exceptions.InvalidProxyMessageRaised when an HTTP proxy response is malformed.
class
src.websockets.exceptions.InvalidProxyStatusRaised when an HTTP proxy rejects the connection.
class
src.websockets.exceptions.InvalidStateRaised when sending a frame is forbidden in the current state.
class
src.websockets.exceptions.ProtocolErrorRaised when receiving or sending a frame that breaks the protocol.
class
src.websockets.exceptions.ProxyErrorRaised when failing to connect to a proxy.
class
src.websockets.exceptions.WebSocketExceptionBase class for all exceptions defined by websockets.
class
src.websockets.extensions.base.ClientExtensionFactoryBase class for client-side extension factories.
class
src.websockets.extensions.base.ExtensionBase class for extensions.
method
src.websockets.extensions.base.Extension.decode(frame:Frame, *max_size:int | None=None) -> FrameDecode an incoming frame.
method
src.websockets.extensions.base.Extension.encode(frame:Frame) -> FrameEncode an outgoing frame.
class
src.websockets.extensions.base.ServerExtensionFactoryBase class for server-side extension factories.
class
src.websockets.extensions.permessage_deflate.PerMessageDeflatePer-Message Deflate extension.
method
src.websockets.extensions.permessage_deflate.PerMessageDeflate.decode(frame:Frame, *max_size:int | None=None) -> FrameDecode an incoming frame.
method
src.websockets.extensions.permessage_deflate.PerMessageDeflate.encode(frame:Frame) -> FrameEncode an outgoing frame.
class
src.websockets.frames.CloseCode and reason for WebSocket close frames.
method
src.websockets.frames.Close.parse(data:BytesLike) -> SelfParse the payload of a close frame.
method
src.websockets.frames.Close.serialize() -> bytesSerialize the payload of a close frame.
class
src.websockets.frames.CloseCodeClose code values for WebSocket close frames.
class
src.websockets.frames.FrameWebSocket frame.
method
src.websockets.frames.Frame.check() -> NoneCheck that reserved bits and opcode have acceptable values.
method
src.websockets.frames.Frame.serialize(*mask:bool, *extensions:Sequence[extensions.Extension] | None=None) -> bytesSerialize a WebSocket frame.
class
src.websockets.frames.OpcodeOpcode values for WebSocket frames.
func
src.websockets.frames.is_utf8_fragment(data:bytes, must_start_clean:bool=False, must_end_clean:bool=False) -> boolGuess if data is a fragment of UTF-8 text.
func
src.websockets.headers.build_authorization_basic(username:str, password:str) -> strBuild an ``Authorization`` header for HTTP Basic Auth.
func
src.websockets.headers.build_extension(extensions:Sequence[ExtensionHeader]) -> strBuild a ``Sec-WebSocket-Extensions`` header.
func
src.websockets.headers.build_extension_item(name:ExtensionName, parameters:Sequence[ExtensionParameter]) -> strBuild an extension definition.
func
src.websockets.headers.build_host(host:str, port:int, secure:bool, *always_include_port:bool=False) -> strBuild a ``Host`` header.
func
src.websockets.headers.build_quoted_string(value:str) -> strFormat ``value`` as a quoted string.
func
src.websockets.headers.build_subprotocol(subprotocols:Sequence[Subprotocol]) -> strBuild a ``Sec-WebSocket-Protocol`` header.
func
src.websockets.headers.build_www_authenticate_basic(realm:str) -> strBuild a ``WWW-Authenticate`` header for HTTP Basic Auth.
func
src.websockets.headers.parse_OWS(header:str, pos:int) -> intParse optional whitespace from ``header`` at the given position.
func
src.websockets.headers.parse_authorization_basic(header:str) -> tuple[str, str]Parse an ``Authorization`` header for HTTP Basic Auth.
func
src.websockets.headers.parse_connection(header:str) -> list[ConnectionOption]Parse a ``Connection`` header.
func
src.websockets.headers.parse_end(header:str, pos:int, header_name:str) -> NoneCheck that parsing reached the end of header.
func
src.websockets.headers.parse_extension(header:str) -> list[ExtensionHeader]Parse a ``Sec-WebSocket-Extensions`` header.
func
src.websockets.headers.parse_subprotocol(header:str) -> list[Subprotocol]Parse a ``Sec-WebSocket-Protocol`` header.
func
src.websockets.headers.parse_token(header:str, pos:int, header_name:str) -> tuple[str, int]Parse a token from ``header`` at the given position.
func
src.websockets.headers.parse_token68(header:str, pos:int, header_name:str) -> tuple[str, int]Parse a token68 from ``header`` at the given position.
func
src.websockets.headers.parse_upgrade(header:str) -> list[UpgradeProtocol]Parse an ``Upgrade`` header.
func
src.websockets.headers.peek_ahead(header:str, pos:int) -> str | NoneReturn the next character from ``header`` at the given position.
class
src.websockets.http11.RequestWebSocket handshake request.
method
src.websockets.http11.Request.parse(read_line:Callable[[int, type[Exception]], Generator[None, None, bytes | bytearray]]) -> Generator[None, None, Request]Parse a WebSocket handshake request.
method
src.websockets.http11.Request.serialize() -> bytesSerialize a WebSocket handshake request.
class
src.websockets.http11.ResponseWebSocket handshake response.
method
src.websockets.http11.Response.serialize() -> bytesSerialize a WebSocket handshake response.
func
src.websockets.http11.d(value:bytes | bytearray) -> strDecode a bytestring for interpolating into an error message.
func
src.websockets.http11.parse_headers(read_line:Callable[[int, type[Exception]], Generator[None, None, bytes | bytearray]]) -> Generator[None, None, Headers]Parse HTTP headers.
func
src.websockets.http11.parse_line(read_line:Callable[[int, type[Exception]], Generator[None, None, bytes | bytearray]], too_long_exc_type:type[Exception]=SecurityError) -> Generator[None, None, bytes | bytearray]Parse a single line.
func
src.websockets.imports.import_name(name:str, source:str, namespace:dict[str, Any]) -> AnyImport ``name`` from ``source`` in ``namespace``.
func
src.websockets.imports.lazy_import(namespace:dict[str, Any], aliases:dict[str, str] | None=None, deprecated_aliases:dict[str, str] | None=None) -> NoneProvide lazy, module-level imports.
class
src.websockets.legacy.client.ConnectConnect to the WebSocket server at ``uri``.
class
src.websockets.legacy.client.WebSocketClientProtocolWebSocket client connection.
class
src.websockets.legacy.exceptions.RedirectHandshakeRaised when a handshake gets redirected.
method
src.websockets.legacy.framing.Frame.read(reader:Callable[[int], Awaitable[bytes]], *mask:bool, *max_size:int | None=None, *extensions:Sequence[extensions.Extension] | None=None) -> FrameRead a WebSocket frame.
method
src.websockets.legacy.framing.Frame.write(write:Callable[[bytes], Any], *mask:bool, *extensions:Sequence[extensions.Extension] | None=None) -> NoneWrite a WebSocket frame.
func
src.websockets.legacy.framing.parse_close(data:bytes) -> tuple[int, str]Parse the payload from a close frame.
func
src.websockets.legacy.framing.prepare_ctrl(data:DataLike) -> bytesConvert a string or byte-like object to bytes.
func
src.websockets.legacy.framing.serialize_close(code:int, reason:str) -> bytesSerialize the payload for a close frame.
func
src.websockets.legacy.handshake.build_request(headers:Headers) -> strBuild a handshake request to send to the server.
func
src.websockets.legacy.handshake.build_response(headers:Headers, key:str) -> NoneBuild a handshake response to send to the client.
func
src.websockets.legacy.handshake.check_request(headers:Headers) -> strCheck a handshake request received from the client.
func
src.websockets.legacy.handshake.check_response(headers:Headers, key:str) -> NoneCheck a handshake response received from the server.
func
src.websockets.legacy.http.d(value:bytes) -> strDecode a bytestring for interpolating into an error message.
func
src.websockets.legacy.http.read_headers(stream:asyncio.StreamReader) -> HeadersRead HTTP headers from ``stream``.
func
src.websockets.legacy.http.read_line(stream:asyncio.StreamReader) -> bytesRead a single line from ``stream``.
class
src.websockets.legacy.protocol.WebSocketCommonProtocolWebSocket connection.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.close(code:int=CloseCode.NORMAL_CLOSURE, reason:str='') -> NonePerform the closing handshake.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.close_connection() -> None7.1.1.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.close_transport() -> NoneClose the TCP connection.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.connection_lost(exc:Exception | None) -> None7.1.4.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.connection_made(transport:asyncio.BaseTransport) -> NoneConfigure write buffer limits.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.ensure_open() -> NoneCheck that the WebSocket connection is open.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.eof_received() -> NoneClose the transport after receiving EOF.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.fail_connection(code:int=CloseCode.ABNORMAL_CLOSURE, reason:str='') -> None7.1.7.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.local_address() -> AnyLocal address of the connection.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.ping(data:DataLike | None=None) -> Awaitable[float]Send a Ping_.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.pong(data:DataLike=b'') -> NoneSend a Pong_.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.read_data_frame(max_size:int | None) -> Frame | NoneRead a single data frame from the connection.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.read_frame(max_size:int | None) -> FrameRead a single frame from the connection.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.read_message() -> Data | NoneRead a single message from the connection.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.recv() -> DataReceive the next message.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.remote_address() -> AnyRemote address of the connection.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.send(message:DataLike | Iterable[DataLike] | AsyncIterable[DataLike]) -> NoneSend a message.
method
src.websockets.legacy.protocol.WebSocketCommonProtocol.wait_closed() -> NoneWait until the connection is closed.
class
src.websockets.legacy.server.WebSocketServerWebSocket server returned by :func:`serve`.
method
src.websockets.legacy.server.WebSocketServer.close(close_connections:bool=True) -> NoneClose the server.
method
src.websockets.legacy.server.WebSocketServer.get_loop() -> asyncio.AbstractEventLoopSee :meth:`asyncio.Server.get_loop`.
method
src.websockets.legacy.server.WebSocketServer.is_serving() -> boolSee :meth:`asyncio.Server.is_serving`.
method
src.websockets.legacy.server.WebSocketServer.register(protocol:WebSocketServerProtocol) -> NoneRegister a connection with this server.
method
src.websockets.legacy.server.WebSocketServer.serve_forever() -> NoneSee :meth:`asyncio.Server.serve_forever`.
method
src.websockets.legacy.server.WebSocketServer.sockets() -> Iterable[socket.socket]See :attr:`asyncio.Server.sockets`.
method
src.websockets.legacy.server.WebSocketServer.start_serving() -> NoneSee :meth:`asyncio.Server.start_serving`.
method
src.websockets.legacy.server.WebSocketServer.unregister(protocol:WebSocketServerProtocol) -> NoneUnregister a connection with this server.
method
src.websockets.legacy.server.WebSocketServer.wait_closed() -> NoneWait until the server is closed.
method
src.websockets.legacy.server.WebSocketServer.wrap(server:asyncio.base_events.Server) -> NoneAttach to a given :class:`~asyncio.Server`.
class
src.websockets.legacy.server.WebSocketServerProtocolWebSocket server connection.
method
src.websockets.legacy.server.WebSocketServerProtocol.process_origin(headers:Headers, origins:Sequence[Origin | None] | None=None) -> Origin | NoneHandle the Origin HTTP request header.
class
src.websockets.protocol.ProtocolSans-I/O implementation of a WebSocket connection.
method
src.websockets.protocol.Protocol.data_to_send() -> list[bytes]Obtain data to send to the network.
method
src.websockets.protocol.Protocol.discard() -> Generator[None]Discard incoming data.
method
src.websockets.protocol.Protocol.fail(code:CloseCode | int, reason:str='') -> None`Fail the WebSocket connection`_.
method
src.websockets.protocol.Protocol.parse() -> Generator[None]Parse incoming data into frames.
method
src.websockets.protocol.Protocol.receive_data(data:bytes | bytearray) -> NoneReceive data from the network.
method
src.websockets.protocol.Protocol.receive_eof() -> NoneReceive the end of the data stream from the network.
method
src.websockets.protocol.Protocol.recv_frame(frame:Frame) -> NoneProcess an incoming frame.
method
src.websockets.protocol.Protocol.send_binary(data:BytesLike, fin:bool=True) -> NoneSend a `Binary frame`_.
method
src.websockets.protocol.Protocol.send_close(code:CloseCode | int | None=None, reason:str='') -> NoneSend a `Close frame`_.
method
src.websockets.protocol.Protocol.send_continuation(data:BytesLike, fin:bool) -> NoneSend a `Continuation frame`_.
method
src.websockets.protocol.Protocol.send_ping(data:BytesLike) -> NoneSend a `Ping frame`_.
method
src.websockets.protocol.Protocol.send_pong(data:BytesLike) -> NoneSend a `Pong frame`_.
method
src.websockets.protocol.Protocol.send_text(data:BytesLike, fin:bool=True) -> NoneSend a `Text frame`_.
method
src.websockets.protocol.Protocol.state() -> StateState of the WebSocket connection.
class
src.websockets.protocol.SideA WebSocket connection is either a server or a client.
class
src.websockets.protocol.StateA WebSocket connection is in one of these four states.
class
src.websockets.proxy.ProxyProxy address.
func
src.websockets.proxy.parse_proxy(proxy:str) -> ProxyParse and validate a proxy.
method
src.websockets.server.ServerProtocol.accept(request:Request) -> ResponseCreate a handshake response to accept the connection.
method
src.websockets.server.ServerProtocol.process_origin(headers:Headers) -> Origin | NoneHandle the Origin HTTP request header.
method
src.websockets.server.ServerProtocol.reject(status:StatusLike, text:str) -> ResponseCreate a handshake response to reject the connection.
method
src.websockets.server.ServerProtocol.send_response(response:Response) -> NoneSend a handshake response to the client.
class
src.websockets.streams.StreamReaderGenerator-based stream reader.
method
src.websockets.streams.StreamReader.discard() -> NoneDiscard all buffered data, but don't end the stream.
method
src.websockets.streams.StreamReader.feed_data(data:bytes | bytearray) -> NoneWrite data to the stream.
method
src.websockets.streams.StreamReader.feed_eof() -> NoneEnd the stream.
method
src.websockets.streams.StreamReader.read_exact(n:int) -> Generator[None, None, bytearray]Read a given number of bytes from the stream.
method
src.websockets.streams.StreamReader.read_line(m:int, too_long_exc_type:type[Exception]=RuntimeError) -> Generator[None, None, bytearray]Read a LF-terminated line from the stream.
method
src.websockets.streams.StreamReader.read_to_eof(m:int, too_long_exc_type:type[Exception]=RuntimeError) -> Generator[None, None, bytearray]Read all bytes from the stream.
method
src.websockets.sync.client.ClientConnection.handshake(additional_headers:HeadersLike | None=None, user_agent_header:str | None=USER_AGENT, timeout:float | None=None) -> NonePerform the opening handshake.
method
src.websockets.sync.client.ClientConnection.process_event(event:Event) -> NoneProcess one incoming event.
class
src.websockets.sync.client.SSLSSLSocketSocket-like object providing TLS-in-TLS.
method
src.websockets.sync.connection.Connection.acknowledge_pings(data:bytes) -> NoneAcknowledge pings when receiving a pong.
method
src.websockets.sync.connection.Connection.close(code:CloseCode | int=CloseCode.NORMAL_CLOSURE, reason:str='') -> NonePerform the closing handshake.
method
src.websockets.sync.connection.Connection.close_socket() -> NoneShutdown and close socket.
method
src.websockets.sync.connection.Connection.local_address() -> AnyLocal address of the connection.
method
src.websockets.sync.connection.Connection.ping(data:DataLike | None=None, *ack_on_close:bool=False) -> threading.EventSend a Ping_.
method
src.websockets.sync.connection.Connection.pong(data:DataLike=b'') -> NoneSend a Pong_.
method
src.websockets.sync.connection.Connection.process_event(event:Event) -> NoneProcess one incoming event.
method
src.websockets.sync.connection.Connection.remote_address() -> AnyRemote address of the connection.
method
src.websockets.sync.connection.Connection.send(message:DataLike | Iterable[DataLike], *text:bool | None=None) -> NoneSend a message.
method
src.websockets.sync.connection.Connection.send_data() -> NoneSend outgoing data.
method
src.websockets.sync.connection.Connection.set_recv_exc(exc:BaseException | None) -> NoneSet recv_exc, if not set yet.
class
src.websockets.sync.messages.AssemblerAssemble messages from frames.
method
src.websockets.sync.messages.Assembler.close() -> NoneEnd the stream of frames.
method
src.websockets.sync.messages.Assembler.put(frame:Frame) -> NoneAdd ``frame`` to the next message.
class
src.websockets.sync.router.RouterWebSocket router supporting :func:`route`.
method
src.websockets.sync.router.Router.handler(connection:ServerConnection) -> NoneHandle a connection.
method
src.websockets.sync.router.Router.route_request(connection:ServerConnection, request:Request) -> Response | NoneRoute incoming request.
class
src.websockets.sync.server.ServerWebSocket server returned by :func:`serve`.
method
src.websockets.sync.server.Server.connections() -> set[ServerConnection]Set of active connections.
method
src.websockets.sync.server.Server.fileno() -> intSee :meth:`socketserver.BaseServer.fileno`.
method
src.websockets.sync.server.Server.serve_forever() -> NoneSee :meth:`socketserver.BaseServer.serve_forever`.
method
src.websockets.sync.server.Server.shutdown(close_connections:bool=True, code:CloseCode | int=CloseCode.GOING_AWAY, reason:str='') -> NoneClose the server.
func
src.websockets.sync.server.process_request(connection:ServerConnection, request:Request) -> Response | NonePerform HTTP Basic Authentication.
func
src.websockets.sync.server.sock_handler(sock:socket.socket, addr:Any) -> NoneHandle the lifecycle of a WebSocket connection.
class
src.websockets.sync.utils.DeadlineManage timeouts across multiple steps.
method
src.websockets.sync.utils.Deadline.timeout(*raise_if_elapsed:bool=True) -> float | NoneCalculate a timeout from a deadline.
method
src.websockets.trio.client.ClientConnection.handshake(additional_headers:HeadersLike | None=None, user_agent_header:str | None=USER_AGENT) -> NonePerform the opening handshake.
method
src.websockets.trio.client.ClientConnection.process_event(event:Event) -> NoneProcess one incoming event.
class
src.websockets.trio.client.connectConnect to the WebSocket server at ``uri``.
method
src.websockets.trio.client.connect.enable_tls(stream:trio.abc.Stream) -> trio.abc.StreamEnable TLS on the connection.
method
src.websockets.trio.client.connect.open_connection(nursery:trio.Nursery) -> ClientConnectionCreate a WebSocket connection.
class
src.websockets.trio.connection.Connection:mod:`trio` implementation of a WebSocket connection.
method
src.websockets.trio.connection.Connection.acknowledge_pings(data:bytes) -> NoneAcknowledge pings when receiving a pong.
method
src.websockets.trio.connection.Connection.aclose(code:CloseCode | int=CloseCode.NORMAL_CLOSURE, reason:str='') -> NonePerform the closing handshake.
method
src.websockets.trio.connection.Connection.close_stream() -> NoneShutdown and close stream.
method
src.websockets.trio.connection.Connection.local_address() -> AnyLocal address of the connection.
method
src.websockets.trio.connection.Connection.ping(data:DataLike | None=None, *ack_on_close:bool=False) -> trio.EventSend a Ping_.
method
src.websockets.trio.connection.Connection.pong(data:DataLike=b'') -> NoneSend a Pong_.
method
src.websockets.trio.connection.Connection.process_event(event:Event) -> NoneProcess one incoming event.
method
src.websockets.trio.connection.Connection.remote_address() -> AnyRemote address of the connection.
method
src.websockets.trio.connection.Connection.send(message:DataLike | Iterable[DataLike] | AsyncIterable[DataLike], *text:bool | None=None) -> NoneSend a message.
method
src.websockets.trio.connection.Connection.send_data() -> NoneSend outgoing data.
method
src.websockets.trio.connection.Connection.set_recv_exc(exc:BaseException | None) -> NoneSet recv_exc, if not set yet.
method
src.websockets.trio.connection.Connection.wait_closed() -> NoneWait until the connection is closed.
class
src.websockets.trio.messages.AssemblerAssemble messages from frames.
method
src.websockets.trio.messages.Assembler.close() -> NoneEnd the stream of frames.
method
src.websockets.trio.messages.Assembler.put(frame:Frame) -> NoneAdd ``frame`` to the next message.
class
src.websockets.trio.router.RouterWebSocket router supporting :func:`route`.
method
src.websockets.trio.router.Router.handler(connection:ServerConnection) -> NoneHandle a connection.
method
src.websockets.trio.router.Router.route_request(connection:ServerConnection, request:Request) -> Response | NoneRoute incoming request.
class
src.websockets.trio.server.ServerWebSocket server returned by :func:`serve`.
method
src.websockets.trio.server.Server.aclose(close_connections:bool=True, code:CloseCode | int=CloseCode.GOING_AWAY, reason:str='') -> NoneClose the server.
method
src.websockets.trio.server.Server.connections() -> set[ServerConnection]Set of active connections.
func
src.websockets.trio.server.stream_handler(stream:trio.abc.Stream) -> NoneHandle the lifecycle of a WebSocket connection.
func
src.websockets.trio.utils.race_events(*events:trio.Event) -> NoneWait for any of the given events to be set.
class
src.websockets.uri.WebSocketURIWebSocket URI.
func
src.websockets.uri.parse_uri(uri:str) -> WebSocketURIParse and validate a WebSocket URI.
func
src.websockets.utils.accept_key(key:str) -> strCompute the value of the Sec-WebSocket-Accept header.
func
src.websockets.utils.apply_mask(data:BytesLike, mask:bytes | bytearray) -> bytesApply masking to the data of a WebSocket message.
func
src.websockets.utils.generate_key() -> strGenerate a random key for the Sec-WebSocket-Key header.
About this data
These signatures were extracted from the public source of python-websockets/websockets
using Python's ast module. Argument names, default values,
type annotations and return types are taken verbatim from the code.
Implementation bodies are never stored. See
how it works for details.