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.1.
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
Hashes for websockets-9.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c8f9debc1dd247c9d2c907413fee7749857e0517f24ca21376f75add59cb4c3 |
|
MD5 | 7d12f898d3fa46f9dfaf2fab625d471c |
|
BLAKE2b-256 | fc3da13517790e42b78d789ba00e32c24f27be498ce4e1538700dfab139619fb |
Hashes for websockets-9.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e22510cdc29bbca25d1e18541e0466f1b8b0d88034ac94343dcd67e89ea56a6 |
|
MD5 | 020fcceea5f44ab42a9a7e974c160f8a |
|
BLAKE2b-256 | 8c4f1ae1c8eb1d2972e65431329df521ae8d35436936a68e2dde7b0fd9f3faca |
Hashes for websockets-9.0-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39b4685fa0d2615f38fc316368f2bfefdb284166849c968ddcc2548dc5ce438a |
|
MD5 | 798a4fabb14113c481ee5cd50d3142ec |
|
BLAKE2b-256 | 9500dc1292909116fa695955b08aa5331c3f30354d091a20c6cdcbc31bfbec68 |
Hashes for websockets-9.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd5b2cf0fdab90dabecc0a37cef62ebfa0a0c7fd1df2d77c998769fd66fbcbf3 |
|
MD5 | 79862ef5b8abe752aaab0aba22aebb7e |
|
BLAKE2b-256 | 7583e3a89eb269ae55ecdf022edfc920c5cc43b9b5f6509422916cb177b67331 |
Hashes for websockets-9.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25a8540b9139b29b586c8703f852eb120d9458ea3a6fa43e74d7ad8b9ecab857 |
|
MD5 | 9f87c8b11be9848551e19db72bdf3647 |
|
BLAKE2b-256 | dccc15042209b8753f9680496959f22361e45ffcdf58ae15debf622d4cfe405a |
Hashes for websockets-9.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e6b12d5d990010990920d56ad911e44b3053a5e2dbc29059e3e170f18b13e8e |
|
MD5 | e2f15a29ab4c5eca7de958afa841305f |
|
BLAKE2b-256 | 2b927470bc876145601bcd263358c8a05d11cbf6a4c8d07d10ae4469559c54dd |
Hashes for websockets-9.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81c036e600decfd70d63c847495edf8d18510d5afb3ffe3ac84a2ce8498e2bda |
|
MD5 | d708c93fc71fded14f7a301e06db713b |
|
BLAKE2b-256 | 08fbd2b5881007fe2dc62e5a3bddf1d47d900a07f52fc3cdaa7e0b337e363249 |
Hashes for websockets-9.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4605f0fc7d857b60c2de622560d4c363eb1e5f34b6ccc3180d6b4f35320e9533 |
|
MD5 | 300d599306746494d0d3ea6997016724 |
|
BLAKE2b-256 | 81ac0bd9dcc15759a1a3b1f744ebf71c5cd85ed28586fbda5358be6daafe16b7 |
Hashes for websockets-9.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | addae134de73e4a8728e4281581f99c20ac80bc03db655a27d7c81338a499e74 |
|
MD5 | 431ff0691adb8b13722a47e89e3b65a7 |
|
BLAKE2b-256 | 485a672640b2e4e5e8de13b19b35d31e1ecf1fb76c3df9eb8e380c6ebc068731 |
Hashes for websockets-9.0-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfd757e3834ec64755dc773487048d2675886e79da016816f763b9a8ab1c9ef7 |
|
MD5 | f7a5a6c27dd9e4b108c3565c6c1726a5 |
|
BLAKE2b-256 | fa0978397183b157f4bac9e1f110fc9bea0ed1bfe9695b55beabbef304260c9e |
Hashes for websockets-9.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25256f89611412995b49711eb2df87d051e83e527ec696b20eaf2acd980d3ea2 |
|
MD5 | 9e6336faaea537af60ca958ce3d8b0b4 |
|
BLAKE2b-256 | c2e986b3baf2b76d8b24970191a7fb4cab294eca22f5396767100d529579b159 |
Hashes for websockets-9.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c39162b38cff046dece4704f31a3bdd685645be13175faa97342ede97b9f79be |
|
MD5 | 1d1d7013af46789bc04c604d56ad6d72 |
|
BLAKE2b-256 | cb76a954d83c0c3f5e61c62896564b51beb9fe16f1dde1f9b65c413df7e7dfc8 |
Hashes for websockets-9.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2c5e178b0559588e8d1e72d84045ff80666678081cf2af3fa51b633c5f33900 |
|
MD5 | 7bec08fdc7738dee68c6fed89e30481f |
|
BLAKE2b-256 | 87fd4c60fde187d23d54057f52c9717e4e861afc1a9a87da5fdcbd1cd36025c5 |
Hashes for websockets-9.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2ac419d91ea151ce05402ad7df228eb0ead41f79d365e884667b0da5c994664 |
|
MD5 | 4e20fae5858f04fad858cf5e4a7e38e2 |
|
BLAKE2b-256 | fd7fec8693972a46d7a6a68ce644ba0c32e891eaf3dc03403cf824f956c79b64 |
Hashes for websockets-9.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9095b28d59f2497afe96e85982d9f8b353bec5d8881f3f3e987c1e6a3a07631 |
|
MD5 | 30e0a9f6438ec01282f3a2b07b0e4994 |
|
BLAKE2b-256 | fc4823a600b0d147f8e39c9ac3b48233254aa43d5cecc475b454d41496b17ca1 |
Hashes for websockets-9.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebbb6ddac77a56d06f62a255e7e743d4b37b9d242171e4478c58782337cb5c42 |
|
MD5 | ce909001d245ad809592ddb2bfe510f2 |
|
BLAKE2b-256 | a265cc05e185994de281bf18358e4800455d4c9a3cc5ad5d8f116f11162c12a0 |
Hashes for websockets-9.0-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b23e3bee637eceb74542571be6c723e8b86676192265e384502a0792509598c |
|
MD5 | 1837c04113a51b7b301d6a4ade354756 |
|
BLAKE2b-256 | 512be2fb97def3953048b186110cf2f597d4b551f973ad9c3e03a361fbb5dac7 |
Hashes for websockets-9.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b791cdcf50574152c4e5007e2857031b9b3f0f0c86ccad6ccad66a32fe9e5c1c |
|
MD5 | bebcb2f28dbca960c6a65171662f4070 |
|
BLAKE2b-256 | de0fff885ae0b1ca753698726ed1698420ee2c30389fd1aafef45c590cc142da |
Hashes for websockets-9.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a0e2446046c957ceda1a0e550e0777b471712d92b1875f072fdbaab0088f940 |
|
MD5 | b9fcc5fe468dba9d9f922ba2e127ab1f |
|
BLAKE2b-256 | b75002b72397b52f96a28a3496ed6c2c98624f113056e50748cf3885026c9774 |
Hashes for websockets-9.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1985c0bbff337c34d88bc0ea9f00a1ab298042f32fe13e75a0acebee51b2df7 |
|
MD5 | 5e6ff4cade03e2e41c5f375922e233ba |
|
BLAKE2b-256 | ea82aa53d2f81f5bb06d9346ef4b8db76411ff9d750b871fcfb7a9ec72cc40fb |
Hashes for websockets-9.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a6ea8bbc6c608daad49fac61efd66ef6769a8591442cfdc7f07589fa09fb218 |
|
MD5 | 5a9c05e84f408e18ca1169d14b39f2c3 |
|
BLAKE2b-256 | fe92e14d87c08e78eac9863ad3a2477c833647cd15b107a6c81bfecadad2acf5 |