Lomond

0.3.3 · abandoned · verified Sun Apr 12

Lomond is a Pythonic WebSocket client library designed for reliability and ease of use, turning a WebSocket connection into an orderly stream of events. It distinguishes itself by providing an event-driven model without requiring explicit threads or callbacks for basic usage. The current version is 0.3.3. However, the library appears to be abandoned, with the last release in 2018 and no recent development activity.

Warnings

Install

Imports

Quickstart

This example demonstrates how to establish a WebSocket connection using Lomond, send a text message, and print received text messages. Lomond provides an event-driven loop where different `event.name` values indicate connection status or received data. The loop will terminate upon disconnection or explicit `break`.

import os
from lomond import WebSocket

# Using a public echo server for demonstration.
# Replace with your actual WebSocket URL.
websocket = WebSocket(os.environ.get('LOMOND_WS_URL', 'wss://echo.websocket.org'))

print(f"Connecting to {websocket.url}...")

for event in websocket:
    if event.name == 'ready':
        print('WebSocket connection established. Sending a message...')
        websocket.send_text('Hello from Lomond!')
    elif event.name == 'text':
        print(f'Received: {event.text}')
        # Optionally close after receiving a message
        websocket.close()
        break
    elif event.name == 'disconnected':
        print(f'Disconnected: {event.reason}')
        break
    else:
        # Other events like 'connecting', 'connected', 'poll', 'closing' might occur.
        # print(f'Event: {event.name}')
        pass

view raw JSON →