vuer.client
Vuer Client - Connect to a Vuer server and send/receive events.
Example usage::
import asyncio from vuer import VuerClient from vuer.events import ClientEvent
class MyEvent(ClientEvent): etype = "MY_EVENT"
async def main(): async with VuerClient(URI="ws://localhost:8012") as client:
Fire-and-forget with @ syntax (no await needed)
client.send @ MyEvent(value={"key": "value"})
Awaitable with parentheses
await client.send(MyEvent(value={"data": 123}))
Receive events from the server
async for event in client: print(f"Received: {event}")
asyncio.run(main())
Configuration via environment variables: VUER_CLIENT_URI: WebSocket URI to connect to (default ws://localhost:8012) WEBSOCKET_MAX_SIZE: Maximum WebSocket message size in bytes (default 256MB)
AsyncAt
Wrapper to support both @ syntax (fire-and-forget) and await for async operations.
AsyncAt.init
VuerClient
Client for connecting to a Vuer server.
Supports sending ClientEvents and receiving ServerEvents via websocket.
Example::
async with VuerClient(URI="ws://localhost:8012") as client:
Using @ syntax (fire and forget)
client.send @ ClientEvent(etype="CUSTOM", value="hello")
Using await
await client.send(ClientEvent(etype="CUSTOM", value="hello"))
event = await client.recv() print(event)
Configuration (via constructor or environment variables): URI: WebSocket URI to connect to (env: VUER_CLIENT_URI, default ws://localhost:8012). WEBSOCKET_MAX_SIZE: Maximum WebSocket message size (env: WEBSOCKET_MAX_SIZE, default 256MB).
VuerClient.init
Initialize the Vuer client.
:param URI: WebSocket URI to connect to (e.g., "ws://localhost:8012") :param WEBSOCKET_MAX_SIZE: Maximum websocket message size in bytes (default 256MB)
VuerClient.connect
Connect to the Vuer server.
:return: Self for chaining
VuerClient.close
Close the connection.
VuerClient.connected
Check if client is connected.
VuerClient.send
Send a ClientEvent to the Vuer server.
Supports both @ syntax and await::
Fire and forget with @ syntax
client.send @ ClientEvent(etype="CUSTOM", value="data")
Awaitable
await client.send(ClientEvent(etype="CUSTOM", value="data"))
:return: AsyncAt wrapper supporting @ and await
VuerClient.recv
Receive a ClientEvent from the server.
:param timeout: Optional timeout in seconds :return: ClientEvent or None if connection closed :raises ConnectionError: If not connected
Public imports
These symbols are available from this module. Their definitions are documented in the linked modules.
ClientEvent—vuer.events.ClientEventServerEvent—vuer.events.ServerEvent