Lomond
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
- breaking The library's last release was in 2018 with explicit Python 3.7 compatibility. It is unlikely to be compatible with newer Python versions (3.8+ onwards, especially 3.12) due to significant changes and deprecations in the Python language and standard library over the years (e.g., removal of `distutils`, changes to Unicode handling). Users attempting to run Lomond on modern Python versions may encounter `ImportError` or other runtime errors.
- gotcha Lomond is an abandoned library. There are no indications of ongoing maintenance, bug fixes, or security updates. Using an unmaintained library can introduce security vulnerabilities and compatibility issues with other modern packages or operating systems.
- gotcha Unhandled exceptions within the event loop will cause Lomond to disconnect the socket without performing a graceful WebSocket closing handshake. This can lead to unexpected client or server state.
- gotcha While Lomond's `WebSocket` objects are explicitly stated as thread-safe, the library itself does not launch any threads for its core operation. If your application requires concurrent processing beyond simple event handling, you will need to manage threading yourself (e.g., running the WebSocket loop in a separate thread).
Install
-
pip install lomond -
pip install wsaccel
Imports
- WebSocket
from lomond import WebSocket
Quickstart
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