Skip to main content

Websocket Client Library

Project description

Dataplicity Lomond

Tranquil WebSockets for Python.

PyPI version PyPI Coverage Status CircleCI

Lomond is a Websocket client which turns a websocket connection in to an orderly stream of events. No threads or callbacks necessary.

How to Use

To connect to a "ws:" or "wss:" WebSocket URL, construct a lomond.WebSocket object then iterate over it. This will yield an event object for each step in the connection process and for any data sent by the server.

You will receive a Binary or Text event when the server sends you a message. You may send a message with the send_binary or send_text methods.

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.

from lomond import WebSocket


websocket = WebSocket('wss://echo.websocket.org')

for event in websocket:
    if event.name == 'poll':
        websocket.send_text('Hello, World')
    elif event.name == 'text':
        print(event.text)

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

Project details


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.2.3.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lomond-0.2.3-py2.py3-none-any.whl (33.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file lomond-0.2.3.tar.gz.

File metadata

  • Download URL: lomond-0.2.3.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for lomond-0.2.3.tar.gz
Algorithm Hash digest
SHA256 617e683243c4e2e52076f01ccb836c49f378c68f4940dd0b1e294c0a63eaf6e6
MD5 f8a969d61cb1f223aba801b6fd854f23
BLAKE2b-256 ead80f7a9c4f61e571a2181c1a9c31a1ad935a01c3f633ddf8a33be12ed79490

See more details on using hashes here.

File details

Details for the file lomond-0.2.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for lomond-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 556095c8bd0b58ec33af0cda3807ddee1496cbf8de533058ef573eff827c52ab
MD5 82c4380bd8c1ba6ae43ae0ee86cf7391
BLAKE2b-256 44385af9da7a7408ed19c70bfe41c482fe04379235dbcd4fc4f94a075512fc34

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page