sdkagent

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

KindCount
Classes55
Functions45
Methods146

API list

classexperiments.json_log_formatter.JSONFormatter
Render logs as JSON.
methodsrc.websockets.asyncio.client.ClientConnection.handshake(additional_headers:HeadersLike | None=None, user_agent_header:str | None=USER_AGENT) -> None
Perform the opening handshake.
methodsrc.websockets.asyncio.client.ClientConnection.process_event(event:Event) -> None
Process one incoming event.
classsrc.websockets.asyncio.client.connect
Connect to the WebSocket server at ``uri``.
methodsrc.websockets.asyncio.connection.Connection.acknowledge_pings(data:bytes) -> None
Acknowledge pings when receiving a pong.
methodsrc.websockets.asyncio.connection.Connection.close(code:CloseCode | int=CloseCode.NORMAL_CLOSURE, reason:str='') -> None
Perform the closing handshake.
methodsrc.websockets.asyncio.connection.Connection.local_address() -> Any
Local address of the connection.
methodsrc.websockets.asyncio.connection.Connection.ping(data:DataLike | None=None) -> Awaitable[float]
Send a Ping_.
methodsrc.websockets.asyncio.connection.Connection.pong(data:DataLike=b'') -> None
Send a Pong_.
methodsrc.websockets.asyncio.connection.Connection.process_event(event:Event) -> None
Process one incoming event.
methodsrc.websockets.asyncio.connection.Connection.remote_address() -> Any
Remote address of the connection.
methodsrc.websockets.asyncio.connection.Connection.send(message:DataLike | Iterable[DataLike] | AsyncIterable[DataLike], *text:bool | None=None) -> None
Send a message.
methodsrc.websockets.asyncio.connection.Connection.send_data() -> None
Send outgoing data.
methodsrc.websockets.asyncio.connection.Connection.set_recv_exc(exc:BaseException | None) -> None
Set recv_exc, if not set yet.
methodsrc.websockets.asyncio.connection.Connection.wait_closed() -> None
Wait until the connection is closed.
classsrc.websockets.asyncio.messages.Assembler
Assemble messages from frames.
methodsrc.websockets.asyncio.messages.Assembler.close() -> None
End the stream of frames.
methodsrc.websockets.asyncio.messages.Assembler.put(frame:Frame) -> None
Add ``frame`` to the next message.
classsrc.websockets.asyncio.messages.SimpleQueue
Simplified version of :class:`asyncio.Queue`.
methodsrc.websockets.asyncio.messages.SimpleQueue.abort() -> None
Close the queue, raising EOFError in get() if necessary.
methodsrc.websockets.asyncio.messages.SimpleQueue.get(block:bool=True) -> T
Remove and return an item from the queue, waiting if necessary.
methodsrc.websockets.asyncio.messages.SimpleQueue.put(item:T) -> None
Put an item into the queue.
methodsrc.websockets.asyncio.messages.SimpleQueue.reset(items:Iterable[T]) -> None
Put back items into an empty, idle queue.
classsrc.websockets.asyncio.router.Router
WebSocket router supporting :func:`route`.
methodsrc.websockets.asyncio.router.Router.handler(connection:ServerConnection) -> None
Handle a connection.
methodsrc.websockets.asyncio.router.Router.route_request(connection:ServerConnection, request:Request) -> Response | None
Route incoming request.
classsrc.websockets.asyncio.server.Server
WebSocket server returned by :func:`serve`.
methodsrc.websockets.asyncio.server.Server.close(close_connections:bool=True, code:CloseCode | int=CloseCode.GOING_AWAY, reason:str='') -> None
Close the server.
methodsrc.websockets.asyncio.server.Server.connections() -> set[ServerConnection]
Set of active connections.
methodsrc.websockets.asyncio.server.Server.get_loop() -> asyncio.AbstractEventLoop
See :meth:`asyncio.Server.get_loop`.
methodsrc.websockets.asyncio.server.Server.is_serving() -> bool
See :meth:`asyncio.Server.is_serving`.
methodsrc.websockets.asyncio.server.Server.serve_forever() -> None
See :meth:`asyncio.Server.serve_forever`.
methodsrc.websockets.asyncio.server.Server.sockets() -> tuple[socket.socket, ...]
See :attr:`asyncio.Server.sockets`.
methodsrc.websockets.asyncio.server.Server.start_serving() -> None
See :meth:`asyncio.Server.start_serving`.
methodsrc.websockets.asyncio.server.Server.wait_closed() -> None
Wait until the server is closed.
funcsrc.websockets.asyncio.server.process_request(connection:ServerConnection, request:Request) -> Response | None
Perform HTTP Basic Authentication.
funcsrc.websockets.asyncio.server.protocol_handler(connection:ServerConnection) -> None
Handle the lifecycle of a WebSocket connection.
funcsrc.websockets.cli.escape(string:str) -> str
Make a string safe for a terminal by escaping control characters.
classsrc.websockets.client.ClientProtocol
Sans-I/O implementation of a WebSocket client connection.
methodsrc.websockets.client.ClientProtocol.connect() -> Request
Create a handshake request to open a connection.
methodsrc.websockets.client.ClientProtocol.process_response(response:Response) -> None
Check a handshake response.
methodsrc.websockets.client.ClientProtocol.send_request(request:Request) -> None
Send a handshake request to the server.
classsrc.websockets.datastructures.Headers
Efficient data structure for manipulating HTTP headers.
methodsrc.websockets.datastructures.Headers.clear() -> None
Remove all headers.
methodsrc.websockets.datastructures.Headers.get_all(key:str) -> list[str]
Return the (possibly empty) list of all values for a header.
methodsrc.websockets.datastructures.Headers.set_insecure(key:str, value:str) -> None
Set a header without validating its value.
methodsrc.websockets.datastructures.Headers.update(*args:HeadersLike, **kwargs:str) -> None
Update from a :class:`Headers` instance and/or keyword arguments.
classsrc.websockets.exceptions.ConcurrencyError
Raised when receiving or sending messages concurrently.
classsrc.websockets.exceptions.InvalidHandshake
Base class for exceptions raised when the opening handshake fails.
classsrc.websockets.exceptions.InvalidHeader
Raised when an HTTP header doesn't have a valid format or value.
classsrc.websockets.exceptions.InvalidHeaderFormat
Raised when an HTTP header cannot be parsed.
classsrc.websockets.exceptions.InvalidHeaderValue
Raised when an HTTP header has a wrong value.
classsrc.websockets.exceptions.InvalidMethod
Raised when a handshake request doesn't use HTTP GET.
classsrc.websockets.exceptions.InvalidOrigin
Raised when the Origin header in a request isn't allowed.
classsrc.websockets.exceptions.InvalidProtocol
Raised when a handshake request doesn't use HTTP/1.1.
classsrc.websockets.exceptions.InvalidProxy
Raised when connecting via a proxy that isn't valid.
classsrc.websockets.exceptions.InvalidProxyMessage
Raised when an HTTP proxy response is malformed.
classsrc.websockets.exceptions.InvalidProxyStatus
Raised when an HTTP proxy rejects the connection.
classsrc.websockets.exceptions.InvalidState
Raised when sending a frame is forbidden in the current state.
classsrc.websockets.exceptions.ProtocolError
Raised when receiving or sending a frame that breaks the protocol.
classsrc.websockets.exceptions.ProxyError
Raised when failing to connect to a proxy.
classsrc.websockets.exceptions.WebSocketException
Base class for all exceptions defined by websockets.
classsrc.websockets.extensions.base.ClientExtensionFactory
Base class for client-side extension factories.
classsrc.websockets.extensions.base.Extension
Base class for extensions.
methodsrc.websockets.extensions.base.Extension.decode(frame:Frame, *max_size:int | None=None) -> Frame
Decode an incoming frame.
methodsrc.websockets.extensions.base.Extension.encode(frame:Frame) -> Frame
Encode an outgoing frame.
classsrc.websockets.extensions.base.ServerExtensionFactory
Base class for server-side extension factories.
classsrc.websockets.extensions.permessage_deflate.PerMessageDeflate
Per-Message Deflate extension.
methodsrc.websockets.extensions.permessage_deflate.PerMessageDeflate.decode(frame:Frame, *max_size:int | None=None) -> Frame
Decode an incoming frame.
methodsrc.websockets.extensions.permessage_deflate.PerMessageDeflate.encode(frame:Frame) -> Frame
Encode an outgoing frame.
classsrc.websockets.frames.Close
Code and reason for WebSocket close frames.
methodsrc.websockets.frames.Close.parse(data:BytesLike) -> Self
Parse the payload of a close frame.
methodsrc.websockets.frames.Close.serialize() -> bytes
Serialize the payload of a close frame.
classsrc.websockets.frames.CloseCode
Close code values for WebSocket close frames.
classsrc.websockets.frames.Frame
WebSocket frame.
methodsrc.websockets.frames.Frame.check() -> None
Check that reserved bits and opcode have acceptable values.
methodsrc.websockets.frames.Frame.serialize(*mask:bool, *extensions:Sequence[extensions.Extension] | None=None) -> bytes
Serialize a WebSocket frame.
classsrc.websockets.frames.Opcode
Opcode values for WebSocket frames.
funcsrc.websockets.frames.is_utf8_fragment(data:bytes, must_start_clean:bool=False, must_end_clean:bool=False) -> bool
Guess if data is a fragment of UTF-8 text.
funcsrc.websockets.headers.build_authorization_basic(username:str, password:str) -> str
Build an ``Authorization`` header for HTTP Basic Auth.
funcsrc.websockets.headers.build_extension(extensions:Sequence[ExtensionHeader]) -> str
Build a ``Sec-WebSocket-Extensions`` header.
funcsrc.websockets.headers.build_extension_item(name:ExtensionName, parameters:Sequence[ExtensionParameter]) -> str
Build an extension definition.
funcsrc.websockets.headers.build_host(host:str, port:int, secure:bool, *always_include_port:bool=False) -> str
Build a ``Host`` header.
funcsrc.websockets.headers.build_quoted_string(value:str) -> str
Format ``value`` as a quoted string.
funcsrc.websockets.headers.build_subprotocol(subprotocols:Sequence[Subprotocol]) -> str
Build a ``Sec-WebSocket-Protocol`` header.
funcsrc.websockets.headers.build_www_authenticate_basic(realm:str) -> str
Build a ``WWW-Authenticate`` header for HTTP Basic Auth.
funcsrc.websockets.headers.parse_OWS(header:str, pos:int) -> int
Parse optional whitespace from ``header`` at the given position.
funcsrc.websockets.headers.parse_authorization_basic(header:str) -> tuple[str, str]
Parse an ``Authorization`` header for HTTP Basic Auth.
funcsrc.websockets.headers.parse_connection(header:str) -> list[ConnectionOption]
Parse a ``Connection`` header.
funcsrc.websockets.headers.parse_end(header:str, pos:int, header_name:str) -> None
Check that parsing reached the end of header.
funcsrc.websockets.headers.parse_extension(header:str) -> list[ExtensionHeader]
Parse a ``Sec-WebSocket-Extensions`` header.
funcsrc.websockets.headers.parse_subprotocol(header:str) -> list[Subprotocol]
Parse a ``Sec-WebSocket-Protocol`` header.
funcsrc.websockets.headers.parse_token(header:str, pos:int, header_name:str) -> tuple[str, int]
Parse a token from ``header`` at the given position.
funcsrc.websockets.headers.parse_token68(header:str, pos:int, header_name:str) -> tuple[str, int]
Parse a token68 from ``header`` at the given position.
funcsrc.websockets.headers.parse_upgrade(header:str) -> list[UpgradeProtocol]
Parse an ``Upgrade`` header.
funcsrc.websockets.headers.peek_ahead(header:str, pos:int) -> str | None
Return the next character from ``header`` at the given position.
classsrc.websockets.http11.Request
WebSocket handshake request.
methodsrc.websockets.http11.Request.parse(read_line:Callable[[int, type[Exception]], Generator[None, None, bytes | bytearray]]) -> Generator[None, None, Request]
Parse a WebSocket handshake request.
methodsrc.websockets.http11.Request.serialize() -> bytes
Serialize a WebSocket handshake request.
classsrc.websockets.http11.Response
WebSocket handshake response.
methodsrc.websockets.http11.Response.serialize() -> bytes
Serialize a WebSocket handshake response.
funcsrc.websockets.http11.d(value:bytes | bytearray) -> str
Decode a bytestring for interpolating into an error message.
funcsrc.websockets.http11.parse_headers(read_line:Callable[[int, type[Exception]], Generator[None, None, bytes | bytearray]]) -> Generator[None, None, Headers]
Parse HTTP headers.
funcsrc.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.
funcsrc.websockets.imports.import_name(name:str, source:str, namespace:dict[str, Any]) -> Any
Import ``name`` from ``source`` in ``namespace``.
funcsrc.websockets.imports.lazy_import(namespace:dict[str, Any], aliases:dict[str, str] | None=None, deprecated_aliases:dict[str, str] | None=None) -> None
Provide lazy, module-level imports.
classsrc.websockets.legacy.client.Connect
Connect to the WebSocket server at ``uri``.
classsrc.websockets.legacy.client.WebSocketClientProtocol
WebSocket client connection.
classsrc.websockets.legacy.exceptions.RedirectHandshake
Raised when a handshake gets redirected.
methodsrc.websockets.legacy.framing.Frame.read(reader:Callable[[int], Awaitable[bytes]], *mask:bool, *max_size:int | None=None, *extensions:Sequence[extensions.Extension] | None=None) -> Frame
Read a WebSocket frame.
methodsrc.websockets.legacy.framing.Frame.write(write:Callable[[bytes], Any], *mask:bool, *extensions:Sequence[extensions.Extension] | None=None) -> None
Write a WebSocket frame.
funcsrc.websockets.legacy.framing.parse_close(data:bytes) -> tuple[int, str]
Parse the payload from a close frame.
funcsrc.websockets.legacy.framing.prepare_ctrl(data:DataLike) -> bytes
Convert a string or byte-like object to bytes.
funcsrc.websockets.legacy.framing.serialize_close(code:int, reason:str) -> bytes
Serialize the payload for a close frame.
funcsrc.websockets.legacy.handshake.build_request(headers:Headers) -> str
Build a handshake request to send to the server.
funcsrc.websockets.legacy.handshake.build_response(headers:Headers, key:str) -> None
Build a handshake response to send to the client.
funcsrc.websockets.legacy.handshake.check_request(headers:Headers) -> str
Check a handshake request received from the client.
funcsrc.websockets.legacy.handshake.check_response(headers:Headers, key:str) -> None
Check a handshake response received from the server.
funcsrc.websockets.legacy.http.d(value:bytes) -> str
Decode a bytestring for interpolating into an error message.
funcsrc.websockets.legacy.http.read_headers(stream:asyncio.StreamReader) -> Headers
Read HTTP headers from ``stream``.
funcsrc.websockets.legacy.http.read_line(stream:asyncio.StreamReader) -> bytes
Read a single line from ``stream``.
classsrc.websockets.legacy.protocol.WebSocketCommonProtocol
WebSocket connection.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.close(code:int=CloseCode.NORMAL_CLOSURE, reason:str='') -> None
Perform the closing handshake.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.close_connection() -> None
7.1.1.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.close_transport() -> None
Close the TCP connection.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.connection_lost(exc:Exception | None) -> None
7.1.4.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.connection_made(transport:asyncio.BaseTransport) -> None
Configure write buffer limits.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.ensure_open() -> None
Check that the WebSocket connection is open.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.eof_received() -> None
Close the transport after receiving EOF.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.fail_connection(code:int=CloseCode.ABNORMAL_CLOSURE, reason:str='') -> None
7.1.7.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.local_address() -> Any
Local address of the connection.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.ping(data:DataLike | None=None) -> Awaitable[float]
Send a Ping_.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.pong(data:DataLike=b'') -> None
Send a Pong_.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.read_data_frame(max_size:int | None) -> Frame | None
Read a single data frame from the connection.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.read_frame(max_size:int | None) -> Frame
Read a single frame from the connection.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.read_message() -> Data | None
Read a single message from the connection.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.recv() -> Data
Receive the next message.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.remote_address() -> Any
Remote address of the connection.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.send(message:DataLike | Iterable[DataLike] | AsyncIterable[DataLike]) -> None
Send a message.
methodsrc.websockets.legacy.protocol.WebSocketCommonProtocol.wait_closed() -> None
Wait until the connection is closed.
classsrc.websockets.legacy.server.WebSocketServer
WebSocket server returned by :func:`serve`.
methodsrc.websockets.legacy.server.WebSocketServer.close(close_connections:bool=True) -> None
Close the server.
methodsrc.websockets.legacy.server.WebSocketServer.get_loop() -> asyncio.AbstractEventLoop
See :meth:`asyncio.Server.get_loop`.
methodsrc.websockets.legacy.server.WebSocketServer.is_serving() -> bool
See :meth:`asyncio.Server.is_serving`.
methodsrc.websockets.legacy.server.WebSocketServer.register(protocol:WebSocketServerProtocol) -> None
Register a connection with this server.
methodsrc.websockets.legacy.server.WebSocketServer.serve_forever() -> None
See :meth:`asyncio.Server.serve_forever`.
methodsrc.websockets.legacy.server.WebSocketServer.sockets() -> Iterable[socket.socket]
See :attr:`asyncio.Server.sockets`.
methodsrc.websockets.legacy.server.WebSocketServer.start_serving() -> None
See :meth:`asyncio.Server.start_serving`.
methodsrc.websockets.legacy.server.WebSocketServer.unregister(protocol:WebSocketServerProtocol) -> None
Unregister a connection with this server.
methodsrc.websockets.legacy.server.WebSocketServer.wait_closed() -> None
Wait until the server is closed.
methodsrc.websockets.legacy.server.WebSocketServer.wrap(server:asyncio.base_events.Server) -> None
Attach to a given :class:`~asyncio.Server`.
classsrc.websockets.legacy.server.WebSocketServerProtocol
WebSocket server connection.
methodsrc.websockets.legacy.server.WebSocketServerProtocol.process_origin(headers:Headers, origins:Sequence[Origin | None] | None=None) -> Origin | None
Handle the Origin HTTP request header.
classsrc.websockets.protocol.Protocol
Sans-I/O implementation of a WebSocket connection.
methodsrc.websockets.protocol.Protocol.data_to_send() -> list[bytes]
Obtain data to send to the network.
methodsrc.websockets.protocol.Protocol.discard() -> Generator[None]
Discard incoming data.
methodsrc.websockets.protocol.Protocol.fail(code:CloseCode | int, reason:str='') -> None
`Fail the WebSocket connection`_.
methodsrc.websockets.protocol.Protocol.parse() -> Generator[None]
Parse incoming data into frames.
methodsrc.websockets.protocol.Protocol.receive_data(data:bytes | bytearray) -> None
Receive data from the network.
methodsrc.websockets.protocol.Protocol.receive_eof() -> None
Receive the end of the data stream from the network.
methodsrc.websockets.protocol.Protocol.recv_frame(frame:Frame) -> None
Process an incoming frame.
methodsrc.websockets.protocol.Protocol.send_binary(data:BytesLike, fin:bool=True) -> None
Send a `Binary frame`_.
methodsrc.websockets.protocol.Protocol.send_close(code:CloseCode | int | None=None, reason:str='') -> None
Send a `Close frame`_.
methodsrc.websockets.protocol.Protocol.send_continuation(data:BytesLike, fin:bool) -> None
Send a `Continuation frame`_.
methodsrc.websockets.protocol.Protocol.send_ping(data:BytesLike) -> None
Send a `Ping frame`_.
methodsrc.websockets.protocol.Protocol.send_pong(data:BytesLike) -> None
Send a `Pong frame`_.
methodsrc.websockets.protocol.Protocol.send_text(data:BytesLike, fin:bool=True) -> None
Send a `Text frame`_.
methodsrc.websockets.protocol.Protocol.state() -> State
State of the WebSocket connection.
classsrc.websockets.protocol.Side
A WebSocket connection is either a server or a client.
classsrc.websockets.protocol.State
A WebSocket connection is in one of these four states.
classsrc.websockets.proxy.Proxy
Proxy address.
funcsrc.websockets.proxy.parse_proxy(proxy:str) -> Proxy
Parse and validate a proxy.
methodsrc.websockets.server.ServerProtocol.accept(request:Request) -> Response
Create a handshake response to accept the connection.
methodsrc.websockets.server.ServerProtocol.process_origin(headers:Headers) -> Origin | None
Handle the Origin HTTP request header.
methodsrc.websockets.server.ServerProtocol.reject(status:StatusLike, text:str) -> Response
Create a handshake response to reject the connection.
methodsrc.websockets.server.ServerProtocol.send_response(response:Response) -> None
Send a handshake response to the client.
classsrc.websockets.streams.StreamReader
Generator-based stream reader.
methodsrc.websockets.streams.StreamReader.discard() -> None
Discard all buffered data, but don't end the stream.
methodsrc.websockets.streams.StreamReader.feed_data(data:bytes | bytearray) -> None
Write data to the stream.
methodsrc.websockets.streams.StreamReader.feed_eof() -> None
End the stream.
methodsrc.websockets.streams.StreamReader.read_exact(n:int) -> Generator[None, None, bytearray]
Read a given number of bytes from the stream.
methodsrc.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.
methodsrc.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.
methodsrc.websockets.sync.client.ClientConnection.handshake(additional_headers:HeadersLike | None=None, user_agent_header:str | None=USER_AGENT, timeout:float | None=None) -> None
Perform the opening handshake.
methodsrc.websockets.sync.client.ClientConnection.process_event(event:Event) -> None
Process one incoming event.
classsrc.websockets.sync.client.SSLSSLSocket
Socket-like object providing TLS-in-TLS.
methodsrc.websockets.sync.connection.Connection.acknowledge_pings(data:bytes) -> None
Acknowledge pings when receiving a pong.
methodsrc.websockets.sync.connection.Connection.close(code:CloseCode | int=CloseCode.NORMAL_CLOSURE, reason:str='') -> None
Perform the closing handshake.
methodsrc.websockets.sync.connection.Connection.close_socket() -> None
Shutdown and close socket.
methodsrc.websockets.sync.connection.Connection.local_address() -> Any
Local address of the connection.
methodsrc.websockets.sync.connection.Connection.ping(data:DataLike | None=None, *ack_on_close:bool=False) -> threading.Event
Send a Ping_.
methodsrc.websockets.sync.connection.Connection.pong(data:DataLike=b'') -> None
Send a Pong_.
methodsrc.websockets.sync.connection.Connection.process_event(event:Event) -> None
Process one incoming event.
methodsrc.websockets.sync.connection.Connection.remote_address() -> Any
Remote address of the connection.
methodsrc.websockets.sync.connection.Connection.send(message:DataLike | Iterable[DataLike], *text:bool | None=None) -> None
Send a message.
methodsrc.websockets.sync.connection.Connection.send_data() -> None
Send outgoing data.
methodsrc.websockets.sync.connection.Connection.set_recv_exc(exc:BaseException | None) -> None
Set recv_exc, if not set yet.
classsrc.websockets.sync.messages.Assembler
Assemble messages from frames.
methodsrc.websockets.sync.messages.Assembler.close() -> None
End the stream of frames.
methodsrc.websockets.sync.messages.Assembler.put(frame:Frame) -> None
Add ``frame`` to the next message.
classsrc.websockets.sync.router.Router
WebSocket router supporting :func:`route`.
methodsrc.websockets.sync.router.Router.handler(connection:ServerConnection) -> None
Handle a connection.
methodsrc.websockets.sync.router.Router.route_request(connection:ServerConnection, request:Request) -> Response | None
Route incoming request.
classsrc.websockets.sync.server.Server
WebSocket server returned by :func:`serve`.
methodsrc.websockets.sync.server.Server.connections() -> set[ServerConnection]
Set of active connections.
methodsrc.websockets.sync.server.Server.fileno() -> int
See :meth:`socketserver.BaseServer.fileno`.
methodsrc.websockets.sync.server.Server.serve_forever() -> None
See :meth:`socketserver.BaseServer.serve_forever`.
methodsrc.websockets.sync.server.Server.shutdown(close_connections:bool=True, code:CloseCode | int=CloseCode.GOING_AWAY, reason:str='') -> None
Close the server.
funcsrc.websockets.sync.server.process_request(connection:ServerConnection, request:Request) -> Response | None
Perform HTTP Basic Authentication.
funcsrc.websockets.sync.server.sock_handler(sock:socket.socket, addr:Any) -> None
Handle the lifecycle of a WebSocket connection.
classsrc.websockets.sync.utils.Deadline
Manage timeouts across multiple steps.
methodsrc.websockets.sync.utils.Deadline.timeout(*raise_if_elapsed:bool=True) -> float | None
Calculate a timeout from a deadline.
methodsrc.websockets.trio.client.ClientConnection.handshake(additional_headers:HeadersLike | None=None, user_agent_header:str | None=USER_AGENT) -> None
Perform the opening handshake.
methodsrc.websockets.trio.client.ClientConnection.process_event(event:Event) -> None
Process one incoming event.
classsrc.websockets.trio.client.connect
Connect to the WebSocket server at ``uri``.
methodsrc.websockets.trio.client.connect.enable_tls(stream:trio.abc.Stream) -> trio.abc.Stream
Enable TLS on the connection.
methodsrc.websockets.trio.client.connect.open_connection(nursery:trio.Nursery) -> ClientConnection
Create a WebSocket connection.
classsrc.websockets.trio.connection.Connection
:mod:`trio` implementation of a WebSocket connection.
methodsrc.websockets.trio.connection.Connection.acknowledge_pings(data:bytes) -> None
Acknowledge pings when receiving a pong.
methodsrc.websockets.trio.connection.Connection.aclose(code:CloseCode | int=CloseCode.NORMAL_CLOSURE, reason:str='') -> None
Perform the closing handshake.
methodsrc.websockets.trio.connection.Connection.close_stream() -> None
Shutdown and close stream.
methodsrc.websockets.trio.connection.Connection.local_address() -> Any
Local address of the connection.
methodsrc.websockets.trio.connection.Connection.ping(data:DataLike | None=None, *ack_on_close:bool=False) -> trio.Event
Send a Ping_.
methodsrc.websockets.trio.connection.Connection.pong(data:DataLike=b'') -> None
Send a Pong_.
methodsrc.websockets.trio.connection.Connection.process_event(event:Event) -> None
Process one incoming event.
methodsrc.websockets.trio.connection.Connection.remote_address() -> Any
Remote address of the connection.
methodsrc.websockets.trio.connection.Connection.send(message:DataLike | Iterable[DataLike] | AsyncIterable[DataLike], *text:bool | None=None) -> None
Send a message.
methodsrc.websockets.trio.connection.Connection.send_data() -> None
Send outgoing data.
methodsrc.websockets.trio.connection.Connection.set_recv_exc(exc:BaseException | None) -> None
Set recv_exc, if not set yet.
methodsrc.websockets.trio.connection.Connection.wait_closed() -> None
Wait until the connection is closed.
classsrc.websockets.trio.messages.Assembler
Assemble messages from frames.
methodsrc.websockets.trio.messages.Assembler.close() -> None
End the stream of frames.
methodsrc.websockets.trio.messages.Assembler.put(frame:Frame) -> None
Add ``frame`` to the next message.
classsrc.websockets.trio.router.Router
WebSocket router supporting :func:`route`.
methodsrc.websockets.trio.router.Router.handler(connection:ServerConnection) -> None
Handle a connection.
methodsrc.websockets.trio.router.Router.route_request(connection:ServerConnection, request:Request) -> Response | None
Route incoming request.
classsrc.websockets.trio.server.Server
WebSocket server returned by :func:`serve`.
methodsrc.websockets.trio.server.Server.aclose(close_connections:bool=True, code:CloseCode | int=CloseCode.GOING_AWAY, reason:str='') -> None
Close the server.
methodsrc.websockets.trio.server.Server.connections() -> set[ServerConnection]
Set of active connections.
funcsrc.websockets.trio.server.stream_handler(stream:trio.abc.Stream) -> None
Handle the lifecycle of a WebSocket connection.
funcsrc.websockets.trio.utils.race_events(*events:trio.Event) -> None
Wait for any of the given events to be set.
classsrc.websockets.uri.WebSocketURI
WebSocket URI.
funcsrc.websockets.uri.parse_uri(uri:str) -> WebSocketURI
Parse and validate a WebSocket URI.
funcsrc.websockets.utils.accept_key(key:str) -> str
Compute the value of the Sec-WebSocket-Accept header.
funcsrc.websockets.utils.apply_mask(data:BytesLike, mask:bytes | bytearray) -> bytes
Apply masking to the data of a WebSocket message.
funcsrc.websockets.utils.generate_key() -> str
Generate 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.

Back to all 805 libraries