An implementation of the WebSocket Protocol (RFC 6455 & 7692)
Project description
What is websockets?
websockets is a library for building WebSocket servers and clients in Python with a focus on correctness and simplicity.
Built on top of asyncio, Python’s standard asynchronous I/O framework, it provides an elegant coroutine-based API.
Documentation is available on Read the Docs.
Here’s how a client sends and receives messages:
#!/usr/bin/env python
import asyncio
import websockets
async def hello(uri):
async with websockets.connect(uri) as websocket:
await websocket.send("Hello world!")
await websocket.recv()
asyncio.get_event_loop().run_until_complete(
hello('ws://localhost:8765'))
And here’s an echo server:
#!/usr/bin/env python
import asyncio
import websockets
async def echo(websocket, path):
async for message in websocket:
await websocket.send(message)
asyncio.get_event_loop().run_until_complete(
websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()
Does that look good?
Why should I use websockets?
The development of websockets is shaped by four principles:
Simplicity: all you need to understand is msg = await ws.recv() and await ws.send(msg); websockets takes care of managing connections so you can focus on your application.
Robustness: websockets is built for production; for example it was the only library to handle backpressure correctly before the issue became widely known in the Python community.
Quality: websockets is heavily tested. Continuous integration fails under 100% branch coverage. Also it passes the industry-standard Autobahn Testsuite.
Performance: memory use is configurable. An extension written in C accelerates expensive operations. It’s pre-compiled for Linux, macOS and Windows and packaged in the wheel format for each system and Python version.
Documentation is a first class concern in the project. Head over to Read the Docs and see for yourself.
Why shouldn’t I use websockets?
If you prefer callbacks over coroutines: websockets was created to provide the best coroutine-based API to manage WebSocket connections in Python. Pick another library for a callback-based API.
If you’re looking for a mixed HTTP / WebSocket library: websockets aims at being an excellent implementation of RFC 6455: The WebSocket Protocol and RFC 7692: Compression Extensions for WebSocket. Its support for HTTP is minimal — just enough for a HTTP health check.
If you want to use Python 2: websockets builds upon asyncio which only works on Python 3. websockets requires Python ≥ 3.6.
What else?
Bug reports, patches and suggestions are welcome!
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
For anything else, please open an issue or send a pull request.
Participants must uphold the Contributor Covenant code of conduct.
websockets is released under the BSD license.
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
Built Distributions
File details
Details for the file websockets-8.0.1.tar.gz
.
File metadata
- Download URL: websockets-8.0.1.tar.gz
- Upload date:
- Size: 57.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3bb8f0b1310b41b727c890353e058b335d1eec18995a82a108ca4784d0e3f94 |
|
MD5 | b20daa8e3676e0e4bb9fcb7e6e3c7d72 |
|
BLAKE2b-256 | dc8111cbf0c9b926ae879deb3e0d39cdd04699378b11890aa8cf24b46549a707 |
File details
Details for the file websockets-8.0.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: websockets-8.0.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 65.7 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 515fc486e026641a416f04d4b24768d39e965628caaf93bb2418013b09333616 |
|
MD5 | a4517e722655c0f1337ae29cec1c8d41 |
|
BLAKE2b-256 | f5bbdea38d95f8ee542ef49b0741e99738cc2d4e90c662f9d0c0d780849e40ff |
File details
Details for the file websockets-8.0.1-cp37-cp37m-win32.whl
.
File metadata
- Download URL: websockets-8.0.1-cp37-cp37m-win32.whl
- Upload date:
- Size: 65.1 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c1116f24778bcd9369b852a862156f4891cdecdc4d722e47fd872ca75d7601d |
|
MD5 | f1f8af62e552fa65dbe4ab9c5970a9c8 |
|
BLAKE2b-256 | 6a5f15876278a369c04ee2874cc375cd9f2b235e8822026fd8bf13249e53db25 |
File details
Details for the file websockets-8.0.1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: websockets-8.0.1-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 72.6 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc6087062e70f8c474a9902296bdc5a071ba5c0e80a8b6072172c8e9ea860f73 |
|
MD5 | 6a815b2a145e095ba2b20210146e872f |
|
BLAKE2b-256 | 69bfcb9f9a33a17e65a540d775ada84c7973d68f46dfeac4676e424dded91155 |
File details
Details for the file websockets-8.0.1-cp37-cp37m-manylinux1_i686.whl
.
File metadata
- Download URL: websockets-8.0.1-cp37-cp37m-manylinux1_i686.whl
- Upload date:
- Size: 72.0 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f44ac3eb78c594e82a327be792748efd87f0fc1bdab47b2ca34545a0085b5f18 |
|
MD5 | 2898c5553f94b8e8f9bd0c80bda03d62 |
|
BLAKE2b-256 | 880b0a15d4edbcc23b49c145fea83e9bf3e7b40e38c83c72c4be9d2470d388f7 |
File details
Details for the file websockets-8.0.1-cp37-cp37m-macosx_10_6_intel.whl
.
File metadata
- Download URL: websockets-8.0.1-cp37-cp37m-macosx_10_6_intel.whl
- Upload date:
- Size: 65.8 kB
- Tags: CPython 3.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f4fa5926c92195e3cebe938ba1e2609ba6640da7fe4a444c65c1b66ed2600a8 |
|
MD5 | e48d5e9f904b1b9542f4ba727431c47d |
|
BLAKE2b-256 | 9a6c82f3e9968a7e021db63920ffc4639e40783b66daa6975e1ed69b14738bb4 |
File details
Details for the file websockets-8.0.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: websockets-8.0.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 65.7 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 265b7fd10c38559a857326ebe1bf5dc45669fd116f9be7e494d2341a1ae26744 |
|
MD5 | bbfdade200746922f520c931eeed3a90 |
|
BLAKE2b-256 | 7c37160c5ef9138fb5265b38601676196b9bbd26e4cabb1afcafda681081794a |
File details
Details for the file websockets-8.0.1-cp36-cp36m-win32.whl
.
File metadata
- Download URL: websockets-8.0.1-cp36-cp36m-win32.whl
- Upload date:
- Size: 65.1 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8495667dbab2554b8b6cb43538d5caf6cc309ba6b7eff005424a2673bfdb1f6e |
|
MD5 | fd36268dcd42d89db2abe869d94aa1a0 |
|
BLAKE2b-256 | 15aee960803d464860aa43f85d224f19876aa97aec5fd1c1cbf4c95a1624924d |
File details
Details for the file websockets-8.0.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: websockets-8.0.1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 72.6 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94febad341c185c90fea741128eff68813e68b530750ac2de8c307f85ce38265 |
|
MD5 | 1179f230fd8038166635cdd1ccce1c08 |
|
BLAKE2b-256 | c1d2bf72435a7d56f94b57efdeae26c76bf0d16f409fd44ff595da745c3fbefd |
File details
Details for the file websockets-8.0.1-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: websockets-8.0.1-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 72.0 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e61e77ef3cae42b9287c571c5da22b811499b32e68aa4f66db2db83234cd04ab |
|
MD5 | c81417c166d635c2c2adec2a2275cd19 |
|
BLAKE2b-256 | 46139f2c6ea45e0b33d6cd1aa7f360b5b83c00f103994610feb3d60d823af7a5 |
File details
Details for the file websockets-8.0.1-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: websockets-8.0.1-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 65.8 kB
- Tags: CPython 3.6m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10cec0881bf992c0c7d67ebafd8d816ef8d498e6cb748b81a328023688b6b66d |
|
MD5 | 111267afb912b60248dfef23867b7a41 |
|
BLAKE2b-256 | c587a62ea9b41034455f4fddc93e83799b2e43b39ca789430245381757fd6c80 |