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.
Metadata
Release files for websockets 8.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| websockets-8.0.1.tar.gz | 57.4 kB | Without provenance | Details for websockets-8.0.1.tar.gz |
Built distributions (wheels)
Total release size: 739.8 kB
Release files / websockets-8.0.1.tar.gz
| Download URL | websockets-8.0.1.tar.gz |
|---|---|
| Size | 57.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3bb8f0b1310b41b727c890353e058b335d1eec18995a82a108ca4784d0e3f94
|
|
BLAKE2b-256 checksum How to use checksums |
dc8111cbf0c9b926ae879deb3e0d39cdd04699378b11890aa8cf24b46549a707
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp37-cp37m-win_amd64.whl
| Download URL | websockets-8.0.1-cp37-cp37m-win_amd64.whl |
|---|---|
| Size | 65.7 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
515fc486e026641a416f04d4b24768d39e965628caaf93bb2418013b09333616
|
|
BLAKE2b-256 checksum How to use checksums |
f5bbdea38d95f8ee542ef49b0741e99738cc2d4e90c662f9d0c0d780849e40ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp37-cp37m-win32.whl
| Download URL | websockets-8.0.1-cp37-cp37m-win32.whl |
|---|---|
| Size | 65.1 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
4c1116f24778bcd9369b852a862156f4891cdecdc4d722e47fd872ca75d7601d
|
|
BLAKE2b-256 checksum How to use checksums |
6a5f15876278a369c04ee2874cc375cd9f2b235e8822026fd8bf13249e53db25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp37-cp37m-manylinux1_x86_64.whl
| Download URL | websockets-8.0.1-cp37-cp37m-manylinux1_x86_64.whl |
|---|---|
| Size | 72.6 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
fc6087062e70f8c474a9902296bdc5a071ba5c0e80a8b6072172c8e9ea860f73
|
|
BLAKE2b-256 checksum How to use checksums |
69bfcb9f9a33a17e65a540d775ada84c7973d68f46dfeac4676e424dded91155
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp37-cp37m-manylinux1_i686.whl
| Download URL | websockets-8.0.1-cp37-cp37m-manylinux1_i686.whl |
|---|---|
| Size | 72.0 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-32 |
|
SHA-256 checksum How to use checksums |
f44ac3eb78c594e82a327be792748efd87f0fc1bdab47b2ca34545a0085b5f18
|
|
BLAKE2b-256 checksum How to use checksums |
880b0a15d4edbcc23b49c145fea83e9bf3e7b40e38c83c72c4be9d2470d388f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp37-cp37m-macosx_10_6_intel.whl
| Download URL | websockets-8.0.1-cp37-cp37m-macosx_10_6_intel.whl |
|---|---|
| Size | 65.8 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
6f4fa5926c92195e3cebe938ba1e2609ba6640da7fe4a444c65c1b66ed2600a8
|
|
BLAKE2b-256 checksum How to use checksums |
9a6c82f3e9968a7e021db63920ffc4639e40783b66daa6975e1ed69b14738bb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp36-cp36m-win_amd64.whl
| Download URL | websockets-8.0.1-cp36-cp36m-win_amd64.whl |
|---|---|
| Size | 65.7 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
265b7fd10c38559a857326ebe1bf5dc45669fd116f9be7e494d2341a1ae26744
|
|
BLAKE2b-256 checksum How to use checksums |
7c37160c5ef9138fb5265b38601676196b9bbd26e4cabb1afcafda681081794a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp36-cp36m-win32.whl
| Download URL | websockets-8.0.1-cp36-cp36m-win32.whl |
|---|---|
| Size | 65.1 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
8495667dbab2554b8b6cb43538d5caf6cc309ba6b7eff005424a2673bfdb1f6e
|
|
BLAKE2b-256 checksum How to use checksums |
15aee960803d464860aa43f85d224f19876aa97aec5fd1c1cbf4c95a1624924d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp36-cp36m-manylinux1_x86_64.whl
| Download URL | websockets-8.0.1-cp36-cp36m-manylinux1_x86_64.whl |
|---|---|
| Size | 72.6 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
94febad341c185c90fea741128eff68813e68b530750ac2de8c307f85ce38265
|
|
BLAKE2b-256 checksum How to use checksums |
c1d2bf72435a7d56f94b57efdeae26c76bf0d16f409fd44ff595da745c3fbefd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp36-cp36m-manylinux1_i686.whl
| Download URL | websockets-8.0.1-cp36-cp36m-manylinux1_i686.whl |
|---|---|
| Size | 72.0 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 |
|
SHA-256 checksum How to use checksums |
e61e77ef3cae42b9287c571c5da22b811499b32e68aa4f66db2db83234cd04ab
|
|
BLAKE2b-256 checksum How to use checksums |
46139f2c6ea45e0b33d6cd1aa7f360b5b83c00f103994610feb3d60d823af7a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / websockets-8.0.1-cp36-cp36m-macosx_10_6_intel.whl
| Download URL | websockets-8.0.1-cp36-cp36m-macosx_10_6_intel.whl |
|---|---|
| Size | 65.8 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
10cec0881bf992c0c7d67ebafd8d816ef8d498e6cb748b81a328023688b6b66d
|
|
BLAKE2b-256 checksum How to use checksums |
c587a62ea9b41034455f4fddc93e83799b2e43b39ca789430245381757fd6c80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for websockets 8.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.