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
Hashes for websockets-5.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8d9823a0eb52b5a2cc39b44c13bf99644f006778459da1d0175bc5e92fd8112 |
|
MD5 | 46210ca35d3dde30ef8a27410d182919 |
|
BLAKE2b-256 | d89018e9415f2035bd182b2269b30f4fc087ff8757c00912cbc3864e516339b3 |
Hashes for websockets-5.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ae1b897c61f8e4306c9a18c5c4ecb695738bd4824f330cc7aa45caa95d971d8 |
|
MD5 | 175f20aa9fec95af103010b27b0eaa7d |
|
BLAKE2b-256 | 54ce0e28c39bcb719932838284bc8bfaf7cfb86262d12bd088a67266992eab34 |
Hashes for websockets-5.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed77c1a7779ff4060920470dc303c9dcba88f22ef769e46868e9bb9ea537ce26 |
|
MD5 | d51e333b4021e1d7b1e7c8bebbb1d782 |
|
BLAKE2b-256 | 72affbd01573d6faf8f897f6645c45e788551b55652e26fe5fd1eaff503f6377 |
Hashes for websockets-5.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d8ce82e5a0c7947b204d0b1abe0f66bc247dc5c605aa5a339df7d91012356e5 |
|
MD5 | cebeed1fb223a0b369edba6b259f5644 |
|
BLAKE2b-256 | cc6e9f550c8194d15946da9b20560389c7e2c3305ea211205eb0f5872847850a |
Hashes for websockets-5.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58f891a21d430b837d61686f50d52efebd415164f9626d10b2000e50ab097439 |
|
MD5 | 5a3e9ca826a3bbca7f786d5a4ab1a46c |
|
BLAKE2b-256 | 4901c4ef4b70fa78ce13521c14a9d5a782be14bcd75010a8f87131343552f069 |
Hashes for websockets-5.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d069ce1bc3af02ad35ee6aef6f82c4b0ce64ea5e3f9585935830cce5c74340bf |
|
MD5 | 6dd7f5a76a7543329d2013240be5582d |
|
BLAKE2b-256 | 0de66c75fe4ab3708d950929deb09108e5d501c38a9eb5138b8b357a5e039f25 |
Hashes for websockets-5.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0f4f59900820cc97d17cc0e7d6e0fc9c0d4a65e906d4e2c09217f89a34f1d71 |
|
MD5 | 67406c7d552b6ae30e027193f750b110 |
|
BLAKE2b-256 | cfdf44bdb9360d0e721c3f16ca192a5384c47cc13e91ac10257194466d02de31 |
Hashes for websockets-5.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2de152acdcffd37e05042ff285f8ef25046c005927d3ea78606ed99524135545 |
|
MD5 | a4eb758de114ce41c7dd9ed41cbd0039 |
|
BLAKE2b-256 | 6eaf8eb36f03a25eb80161fe8c78a4b3ab8b9d22c2b9789968ab05f1e83eddc3 |
Hashes for websockets-5.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe8c6e72c2eaf4d03b9e0d33d7f9f14b9a84f47252b1d4670b798ade572ea360 |
|
MD5 | c92cde73a0f67363f56e588fa22077b1 |
|
BLAKE2b-256 | a13c8d17a1f1adbb1f4389dba6f463d9c1d511e31ac0a8c2875f3608cc77a9a4 |
Hashes for websockets-5.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a21861e60d336d21c6f99958b14b26e977a81eaf8abd5a478e8ee9d091a6cac1 |
|
MD5 | 0666c3d0c3de9b6a42d74c92a2728594 |
|
BLAKE2b-256 | 2df100ea01d64a79a2b73669c27f909ee6c549a30969241fa01595164486a8ce |
Hashes for websockets-5.0-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da93fe3b9ebbd0425539c818eaf73ac55301a3449eaa9349029b39098216dac3 |
|
MD5 | 4478f8169c98cc795501752437fc3e17 |
|
BLAKE2b-256 | a4fa0f10f6b5da7bfbf7c0508f6003979dcedb696f6690f145c181653b1cd773 |
Hashes for websockets-5.0-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9242d6df28fe4c3768c4c6f5b6b6acdfaf1cbc272140c40c0b1c755dc5a5a7bc |
|
MD5 | 289e0b344c7172011decbd8fe3c325a7 |
|
BLAKE2b-256 | 5f2340e60a9fb98119386875f649ae3d55d9e4b29b0dcb1dc391deceba42b222 |
Hashes for websockets-5.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b05205ecdf809fd3c20d597912e9a184d382fcff31c81d86499e5c78aa412346 |
|
MD5 | eee2d39f5ddd0652c8e8b79587c8a244 |
|
BLAKE2b-256 | a77509f6d1a98780421491aabae562887ab196d4dcc2f7066dfe6b2c0c5bcae0 |
Hashes for websockets-5.0-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac76ccd2a5e36c4e980d00042d217635f0f92ef1574d8ca13e81a22add3f801d |
|
MD5 | 2ba05a14a798c1ad439ca5c2795a80b5 |
|
BLAKE2b-256 | 8056a55b4a597d12736dae51271759fd09f299e7b4ac57a03fbeff08eaca3ef1 |
Hashes for websockets-5.0-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d71d1e24deceb18ccea605adef388d9a452b719e09320698e64b522df9029532 |
|
MD5 | 717c2d7a664e5d75fcc79a6ab6d3e3e7 |
|
BLAKE2b-256 | 7077027f36c57357f9b1ce128905e8a77892c84b73f687836ee27f56a4b0cb74 |