Skip to content

Miscellaneous

Lanarky offers client classes to test streaming and websocket endpoints.

StreamingClient

StreamingClient(base_url='http://localhost:8000', client=None)

Test client for streaming server-sent events.

Constructor method.

Parameters:

Name Type Description Default
base_url str

The base URL of the server.

'http://localhost:8000'
client Optional[Client]

The HTTP client to use.

None

stream_response

stream_response(method, path, **kwargs)

Stream data from the server.

Parameters:

Name Type Description Default
method str

The HTTP method to use.

required
path str

The path to stream from.

required
**kwargs dict[str, Any]

The keyword arguments to pass to the HTTP client.

{}

WebSocketClient

WebSocketClient(uri='ws://localhost:8000/ws', mode=DataMode.JSON)

Test client for WebSockets.

Supports 3 data modes: JSON, TEXT, and BYTES.

Constructor method.

Parameters:

Name Type Description Default
uri str

The URI of the websocket.

'ws://localhost:8000/ws'
mode DataMode

The data mode to use.

JSON

connect

connect()

Connect to a websocket and yield data from it.

send

send(message)

Send data to the websocket.

Parameters:

Name Type Description Default
message Any

The data to send.

required

receive

receive(mode=None)

Receive data from the websocket.

Parameters:

Name Type Description Default
mode DataMode

The data mode to use.

None

stream_response

stream_response()

Stream data from the websocket.

Streaming stops until the websocket is closed or the end event is received.

get_logger

get_logger(handler=sys.stderr, **kwargs)

Get a logger instance.

Lanarky uses loguru for logging.

Parameters:

Name Type Description Default
handler Any

The handler to use for the logger.

stderr

Returns:

Type Description
Any

A loguru logger instance.