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.
Here’s a client that says “Hello world!”:
#!/usr/bin/env python
import asyncio
import websockets
async def hello(uri):
async with websockets.connect(uri) as websocket:
await websocket.send("Hello world!")
asyncio.get_event_loop().run_until_complete(
hello('ws://localhost:8765'))
And here’s an echo server (for Python ≥ 3.6):
#!/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? Start here.
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.
Professional support is available if you — or your company — are so inclined. Get in touch.
(If you contribute to websockets and would like to become an official support provider, let me know.)
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.4.
What else?
Bug reports, patches and suggestions welcome! Just open an issue or send a pull request.
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-5.0.1.tar.gz
.
File metadata
- Download URL: websockets-5.0.1.tar.gz
- Upload date:
- Size: 68.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a49d315db5a7a19d55422e1678e8a1c3b9661d7296bef3179fa620cf80b12674 |
|
MD5 | cd2f92f07bca588acd9238b18f6cfbcf |
|
BLAKE2b-256 | 4bc6026da2eeed75a49dd0b72a0c7ed6ee5cb2943e396ca9753eabff7359b27b |
File details
Details for the file websockets-5.0.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: websockets-5.0.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 81.7 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3724acff61ee1029fefc614cf005982338b033998a0b71fbb13a0a2fd99ab6f |
|
MD5 | 25b07362587327a342050f964515597a |
|
BLAKE2b-256 | 97c87d5405e29332a587cbc57b26dce045f25fcabf9ab617c880fe272146adf2 |
File details
Details for the file websockets-5.0.1-cp36-cp36m-win32.whl
.
File metadata
- Download URL: websockets-5.0.1-cp36-cp36m-win32.whl
- Upload date:
- Size: 81.2 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9049ec652713f5132b512d3498c2d37264580714ccc95dbc0f7f9622c3f6da7e |
|
MD5 | 54db527901aa518d70c8abe9524c18d8 |
|
BLAKE2b-256 | 766a4d88a29f6afe511bd9536cd418421d70b5dca3aca8571924e411fdba6c9b |
File details
Details for the file websockets-5.0.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: websockets-5.0.1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 85.3 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c332fc331541c57d40c124089b270d668c25a6b04908bd688969375db7327f |
|
MD5 | 7f2bd3b385303b68f0f0d70b410e01ec |
|
BLAKE2b-256 | 4409c48fd04e293b999aaa1f78c32376d241aa042fce09475f9107ae2e811554 |
File details
Details for the file websockets-5.0.1-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: websockets-5.0.1-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 84.7 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39241fb291c1648e33dc41208be876a5771466291f0f6f7bff8f6732373084bd |
|
MD5 | 4d608d97b4d47d67becb988ccfbfacb9 |
|
BLAKE2b-256 | 9546779d1f3578cd497d24a71bd011a80f17547fc61d227c4a34792e61da8482 |
File details
Details for the file websockets-5.0.1-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: websockets-5.0.1-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 80.1 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b7b561bcbf992edd54e961b89551b5b6073415a0446fe445bd6554d41dabb95 |
|
MD5 | 1f79a8e11137007bc2dcd36392e0fc50 |
|
BLAKE2b-256 | 1681e4d4db405b1ed0cc9a35fb5e74f63e45d33daa0e63e7223ff488507af717 |
File details
Details for the file websockets-5.0.1-cp35-cp35m-win32.whl
.
File metadata
- Download URL: websockets-5.0.1-cp35-cp35m-win32.whl
- Upload date:
- Size: 79.6 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a17c45716178a42cc8f66f587507f01e169a75556749d88f714e4c1d295885d1 |
|
MD5 | f8d5eb38f97d058a09b94a4728f85d32 |
|
BLAKE2b-256 | 81b31bf3a23de098aa9de4241811ea1c61197c096f0e4a78a5de1db702fce54a |
File details
Details for the file websockets-5.0.1-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: websockets-5.0.1-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 83.7 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf34479130704797ce28a478f0b5985abe71ea90999a1c956e15fe0b0b11d0dc |
|
MD5 | aac7346837baab54244632d8e509ace2 |
|
BLAKE2b-256 | fd61614787d6c397196e606f7fadb454189b5fb0466df01ebacd0b9106719e92 |
File details
Details for the file websockets-5.0.1-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: websockets-5.0.1-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 83.1 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a05e42400de009c1c330167cd6d90b300d2364d2dd1e6539d01a6a22901967b |
|
MD5 | 6992fdc1ba6c20b3c2d68787b1d7c4c2 |
|
BLAKE2b-256 | e7dbd210c381c9e3fe45427b95148239f95ed4ba129f9f310c8052d65e62f472 |
File details
Details for the file websockets-5.0.1-cp34-cp34m-win_amd64.whl
.
File metadata
- Download URL: websockets-5.0.1-cp34-cp34m-win_amd64.whl
- Upload date:
- Size: 76.7 kB
- Tags: CPython 3.4m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29b676568e4fcb1a05064473b96243ef4e9391f251b4c485cf7f93507787b459 |
|
MD5 | 407fe049f4820a0eb3223091529dc21c |
|
BLAKE2b-256 | 924b5fc41ecbeb33f7fbf8f39a5457ae995a2125d695e04e6892f5de2cff738f |
File details
Details for the file websockets-5.0.1-cp34-cp34m-win32.whl
.
File metadata
- Download URL: websockets-5.0.1-cp34-cp34m-win32.whl
- Upload date:
- Size: 77.0 kB
- Tags: CPython 3.4m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a911beb8149d7dae9d4c942927c448c05c41dfaa9c002a6bc26e269df932769b |
|
MD5 | 8115f3dda286517ff6c3cad0863227b9 |
|
BLAKE2b-256 | 8398ca5a7a24340a98a247ab4f05bc3578d4856ba577e85aba955453322db1ce |
File details
Details for the file websockets-5.0.1-cp34-cp34m-manylinux1_x86_64.whl
.
File metadata
- Download URL: websockets-5.0.1-cp34-cp34m-manylinux1_x86_64.whl
- Upload date:
- Size: 82.2 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2469c98f2254878a49a6eda248d3ed8a89bbdca85cc316ff72ea15924cec9e1f |
|
MD5 | 4b02f240f2cbaebfba12c4bd6d51bebd |
|
BLAKE2b-256 | f982f6702a719ae1e7921e588297b029e37d8e8f1dc3a6f67258a35a71640a7e |
File details
Details for the file websockets-5.0.1-cp34-cp34m-manylinux1_i686.whl
.
File metadata
- Download URL: websockets-5.0.1-cp34-cp34m-manylinux1_i686.whl
- Upload date:
- Size: 81.7 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 480259ec6e80f28859f23b5c231beb856fb96ab30e64ee621fdaf27da1515604 |
|
MD5 | 5b5a384ad8deaf970156e07995c5c0f9 |
|
BLAKE2b-256 | ea53c0259e4a8f35be59adf4fc8b603727255071cbc127e9444adab49026bf39 |