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)
get_client_info
Gather Python client system information.
Returns a dictionary with system info for the INIT event:
Common fields (shared with browser client):
- client: Always "python" to distinguish from browser clients
- clientVersion: The vuer library version
- timezone: IANA timezone name (e.g., "America/Los_Angeles")
- timezoneOffset: Timezone offset in minutes from UTC
Python-specific fields:
- pythonVersion: Python version string (e.g., "3.11.13")
- platform: Operating system name (e.g., "Darwin", "Linux", "Windows")
- platformVersion: OS kernel version string
- machine: Machine architecture (e.g., "x86_64", "arm64")
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). max_size: Maximum WebSocket message size (env: WEBSOCKET_MAX_SIZE, default 256MB). ssl_verify: Whether to verify SSL certificates (env: VUER_SSL_VERIFY, default True).
VuerClient.init
Initialize the Vuer client.
:param uri: WebSocket URI to connect to (e.g., "ws://localhost:8012") :param max_size: Maximum websocket message size in bytes (default 256MB) :param ssl_verify: Whether to verify SSL certificates (default True, env: VUER_SSL_VERIFY). Set to False for self-signed certs (e.g., ngrok tunnels). :param kwargs: Additional keyword arguments passed to websockets.connect() (e.g., ssl=ssl_context for custom SSL/TLS configuration)
VuerClient.connect
Connect to the Vuer server and send INIT event with client info.
: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.ClientEvent