GitHub

API reference for ws.

WebSockets on the websockets library (extra pyfect-dev[websockets]; Effect's NodeSocket.layerWebSocketConstructorWS; the server side, NodeSocketServer.makeWebSocket, is pyfect.socket.server.make_web_socket).

WsWebSocket is a WebSocketLike over a websockets connection run on the socket loop thread; its events are dispatched there. layer_web_socket_constructor provides WebSocketConstructor with it, and layer_web_socket a client Socket::

socket = make_web_socket("ws://127.0.0.1:8080").pipe(
    provide(layer_web_socket_constructor)
)

Re-exports

Values

AttributeTypeDescription
layer_web_socket_constructorLayer[WebSocketConstructor]

WebSocketConstructor on the websockets client (messages up to 100 MiB).

Classes

Functions

web_socket_constructor

web_socket_constructor(*, max_message_size=DEFAULT_MAX_MESSAGE_SIZE) -> WebSocketConstructorService

WsWebSocket.connect with max_message_size (100 MiB by default, as ws's maxPayload, what pyfect's servers take; None: no limit).

ParameterTypeDescription
max_message_sizeint | None = DEFAULT_MAX_MESSAGE_SIZE

Returns WebSocketConstructorService

def web_socket_constructor(
    *, max_message_size: int | None = DEFAULT_MAX_MESSAGE_SIZE
) -> WebSocketConstructorService:
    """``WsWebSocket.connect`` with ``max_message_size`` (100 MiB by default, as ``ws``'s
    ``maxPayload``, what pyfect's servers take; ``None``: no limit)."""

    def construct(url: str, options: WebSocketClientOptions) -> WebSocketLike:
        return WsWebSocket.connect(url, options, max_message_size=max_message_size)

    return construct

layer_web_socket_constructor_with

layer_web_socket_constructor_with(*, max_message_size=DEFAULT_MAX_MESSAGE_SIZE) -> Layer[WebSocketConstructor]

WebSocketConstructor on the websockets client, taking messages up to max_message_size bytes.

ParameterTypeDescription
max_message_sizeint | None = DEFAULT_MAX_MESSAGE_SIZE

Returns Layer[WebSocketConstructor]

def layer_web_socket_constructor_with(
    *, max_message_size: int | None = DEFAULT_MAX_MESSAGE_SIZE
) -> Layer[WebSocketConstructor]:
    """``WebSocketConstructor`` on the ``websockets`` client, taking messages
    up to ``max_message_size`` bytes."""
    return layer_succeed(
        WebSocketConstructor, web_socket_constructor(max_message_size=max_message_size)
    )

layer_web_socket

layer_web_socket(url, *, open_timeout=None, protocols=None, headers=None, high_water_mark=None, max_message_size=DEFAULT_MAX_MESSAGE_SIZE) -> Layer[Socket]

Socket as a WebSocket client on the websockets library; a message longer than max_message_size bytes closes it with 1009.

ParameterTypeDescription
urlstr | Effect[str]
open_timeoutDurationInput | None = None
protocolsstr | Sequence[str] | None = None
headersMapping[str, str] | None = None
high_water_markint | None = None
max_message_sizeint | None = DEFAULT_MAX_MESSAGE_SIZE

Returns Layer[Socket]

def layer_web_socket(
    url: str | Effect[str],
    *,
    open_timeout: DurationInput | None = None,
    protocols: str | Sequence[str] | None = None,
    headers: Mapping[str, str] | None = None,
    high_water_mark: int | None = None,
    max_message_size: int | None = DEFAULT_MAX_MESSAGE_SIZE,
) -> Layer[Socket]:
    """``Socket`` as a WebSocket client on the ``websockets`` library; a
    message longer than ``max_message_size`` bytes closes it with 1009."""
    client = layer_web_socket_with(
        url,
        open_timeout=open_timeout,
        protocols=protocols,
        headers=headers,
        high_water_mark=high_water_mark,
    )
    constructor = layer_web_socket_constructor_with(max_message_size=max_message_size)
    return client.pipe(layer_provide(constructor))

make_server

make_server(port=0, host=None, **serve_options) -> Effect[SocketServerService, SocketServerError, Scope]

pyfect.socket.server.make_web_socket.

ParameterTypeDescription
portint = 0
hoststr | None = None
serve_optionsAny = {}

Returns Effect[SocketServerService, SocketServerError, Scope]

@deprecated("Use pyfect.socket.server.make_web_socket; ws.make_server is removed in 0.7.0")
def make_server(
    port: int = 0, host: str | None = None, **serve_options: Any
) -> Effect[SocketServerService, SocketServerError, Scope]:
    """``pyfect.socket.server.make_web_socket``."""
    from pyfect.socket._ws_server import make_web_socket

    return make_web_socket(port, host, **serve_options)

layer_server

layer_server(port=0, host=None, **serve_options) -> Layer[SocketServer, SocketServerError]

pyfect.socket.server.layer_web_socket.

ParameterTypeDescription
portint = 0
hoststr | None = None
serve_optionsAny = {}

Returns Layer[SocketServer, SocketServerError]

@deprecated("Use pyfect.socket.server.layer_web_socket; ws.layer_server is removed in 0.7.0")
def layer_server(
    port: int = 0, host: str | None = None, **serve_options: Any
) -> Layer[SocketServer, SocketServerError]:
    """``pyfect.socket.server.layer_web_socket``."""
    from pyfect.socket._ws_server import make_web_socket

    return layer_effect(SocketServer, make_web_socket(port, host, **serve_options))