Websocket Client Library
Project description
# Dataplicity Lomond
Tranquil WebSockets.
Lomond is a Websocket client which turns a websocket connection in to
an orderly stream of _events_. Contrast this with the existing websocket
clients available for Python which follow a more JS-like model of
threads and callbacks.
## How to Use
First construct a `WebSocket` object, then call the `connect` method,
which will return a generator of websocket events.
To run the websocket, simply iterate over the returned generator. You may
do this an another thread, but it isn't required.
## Events
A successful websocket connection will result in a series of events
such as the following:
```
┌──────────────────────┐
│ Connecting │ Contacting server
└──────────────────────┘
│
▼
┌──────────────────────┐ Connected to server (but
│ Connected │ not yet sent data)
└──────────────────────┘
│
▼
┌──────────────────────┐ Negotiated Websocket
│ Ready │ handshake
└──────────────────────┘
│ ┌───────────┐
│ │ │
▼ ▼ │
┌──────────────────────┐ │ Send and receive
│ Binary / Text ─ Poll │──┘ application data
└──────────────────────┘
│
▼
┌──────────────────────┐ Websocket close
│ Closed │ handshake
└──────────────────────┘
│
▼
┌──────────────────────┐
│ Disconnected │ Disconnected TCP/IP
└──────────────────────┘ connection to server
```
## Example
The following is a silly example that connects to a websocket server
(in this case a public echo server), and sends a string of text
every 5 seconds.
```python
from lomond import WebSocket
ws = WebSocket('wss://echo.websocket.org')
for event in ws:
if event.name == 'poll':
ws.send_text('Hello, World')
elif event.name == 'text':
print(event.text)
```
Tranquil WebSockets.
Lomond is a Websocket client which turns a websocket connection in to
an orderly stream of _events_. Contrast this with the existing websocket
clients available for Python which follow a more JS-like model of
threads and callbacks.
## How to Use
First construct a `WebSocket` object, then call the `connect` method,
which will return a generator of websocket events.
To run the websocket, simply iterate over the returned generator. You may
do this an another thread, but it isn't required.
## Events
A successful websocket connection will result in a series of events
such as the following:
```
┌──────────────────────┐
│ Connecting │ Contacting server
└──────────────────────┘
│
▼
┌──────────────────────┐ Connected to server (but
│ Connected │ not yet sent data)
└──────────────────────┘
│
▼
┌──────────────────────┐ Negotiated Websocket
│ Ready │ handshake
└──────────────────────┘
│ ┌───────────┐
│ │ │
▼ ▼ │
┌──────────────────────┐ │ Send and receive
│ Binary / Text ─ Poll │──┘ application data
└──────────────────────┘
│
▼
┌──────────────────────┐ Websocket close
│ Closed │ handshake
└──────────────────────┘
│
▼
┌──────────────────────┐
│ Disconnected │ Disconnected TCP/IP
└──────────────────────┘ connection to server
```
## Example
The following is a silly example that connects to a websocket server
(in this case a public echo server), and sends a string of text
every 5 seconds.
```python
from lomond import WebSocket
ws = WebSocket('wss://echo.websocket.org')
for event in ws:
if event.name == 'poll':
ws.send_text('Hello, World')
elif event.name == 'text':
print(event.text)
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lomond-0.1.6a2.tar.gz
(17.1 kB
view hashes)
Built Distribution
Close
Hashes for lomond-0.1.6a2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1038efd12bffc1c9af516428e029c104885a9f52fad2a91dc479e44c5f875f7c |
|
MD5 | 3d3dc97e30c34f3432ebb1f7213590be |
|
BLAKE2b-256 | 4f0d846fec7cee5b48fac79a01a7f2f092dd39dfb047b95a4a088f1f9f9af284 |