# Dataplicity Lomond
Tranquil WebSockets for Python.
[](https://pypi.org/project/lomond/)
[](https://pypi.org/project/lomond/)
[](https://coveralls.io/github/wildfoundry/dataplicity-lomond?branch=master)
[](https://circleci.com/gh/wildfoundry/dataplicity-lomond/tree/master)
Lomond is a Websocket client which turns a websocket connection in to
an orderly stream of _events_. No threads or callbacks necessary.
- [Documentation](https://lomond.readthedocs.io/)
- [GitHub Repository](https://github.com/wildfoundry/dataplicity-lomond)
- [Blog](https://www.willmcgugan.com/search/?s=lomond)
## 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.
```python
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/wildfoundry/dataplicity-lomond",
"name": "lomond",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "WildFoundry",
"author_email": "willmcgugan@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c0/9e/ef7813c910d4a893f2bc763ce9246269f55cc68db21dc1327e376d6a2d02/lomond-0.3.3.tar.gz",
"platform": "any",
"description": "# Dataplicity Lomond\n\nTranquil WebSockets for Python.\n\n[](https://pypi.org/project/lomond/)\n[](https://pypi.org/project/lomond/)\n[](https://coveralls.io/github/wildfoundry/dataplicity-lomond?branch=master)\n[](https://circleci.com/gh/wildfoundry/dataplicity-lomond/tree/master)\n\nLomond is a Websocket client which turns a websocket connection in to\nan orderly stream of _events_. No threads or callbacks necessary.\n\n- [Documentation](https://lomond.readthedocs.io/)\n\n- [GitHub Repository](https://github.com/wildfoundry/dataplicity-lomond)\n\n- [Blog](https://www.willmcgugan.com/search/?s=lomond)\n\n## How to Use\n\nTo 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.\n\nYou will receive a ``Binary`` or ``Text`` event when the server sends you a message.\nYou may _send_ a message with the ``send_binary`` or ``send_text`` methods.\n\n## Example\n\nThe following is a silly example that connects to a websocket server\n(in this case a public echo server), and sends a string of text\nevery 5 seconds.\n\n\n```python\nfrom lomond import WebSocket\n\n\nwebsocket = WebSocket('wss://echo.websocket.org')\n\nfor event in websocket:\n if event.name == 'poll':\n websocket.send_text('Hello, World')\n elif event.name == 'text':\n print(event.text)\n```\n\n## Events\n\nA successful websocket connection will result in a series of events\nsuch as the following:\n\n```\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 Connecting \u2502 Contacting server\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n \u2502\n \u25bc\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 Connected to server (but\n\u2502 Connected \u2502 not yet sent data)\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n \u2502\n \u25bc\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 Negotiated Websocket\n\u2502 Ready \u2502 handshake\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 \u2502 \u2502\n \u25bc \u25bc \u2502\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 Send and receive\n\u2502 Binary / Text / Poll \u2502\u2500\u2500\u2518 application data\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n \u2502\n \u25bc\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 Websocket close\n\u2502 Closed \u2502 handshake\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n \u2502\n \u25bc\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 Disconnected \u2502 Disconnected TCP/IP\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 connection to server\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Websocket Client Library",
"version": "0.3.3",
"project_urls": {
"Homepage": "https://github.com/wildfoundry/dataplicity-lomond"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0fb102eebed49c754b01b17de7705caa8c4ceecfb4f926cdafc220c863584360",
"md5": "236e9076f7788d76f3390405b89d2eb1",
"sha256": "df1dd4dd7b802a12b71907ab1abb08b8ce9950195311207579379eb3b1553de7"
},
"downloads": -1,
"filename": "lomond-0.3.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "236e9076f7788d76f3390405b89d2eb1",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 35512,
"upload_time": "2018-09-21T15:17:38",
"upload_time_iso_8601": "2018-09-21T15:17:38.686791Z",
"url": "https://files.pythonhosted.org/packages/0f/b1/02eebed49c754b01b17de7705caa8c4ceecfb4f926cdafc220c863584360/lomond-0.3.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c09eef7813c910d4a893f2bc763ce9246269f55cc68db21dc1327e376d6a2d02",
"md5": "ad456d549ca49c42b050f27ff349a2ce",
"sha256": "427936596b144b4ec387ead99aac1560b77c8a78107d3d49415d3abbe79acbd3"
},
"downloads": -1,
"filename": "lomond-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "ad456d549ca49c42b050f27ff349a2ce",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 28789,
"upload_time": "2018-09-21T15:17:43",
"upload_time_iso_8601": "2018-09-21T15:17:43.297567Z",
"url": "https://files.pythonhosted.org/packages/c0/9e/ef7813c910d4a893f2bc763ce9246269f55cc68db21dc1327e376d6a2d02/lomond-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2018-09-21 15:17:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "wildfoundry",
"github_project": "dataplicity-lomond",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"circle": true,
"tox": true,
"lcname": "lomond"
}