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
from websockets import connect
async def hello(uri):
async with connect(uri) as websocket:
await websocket.send("Hello world!")
await websocket.recv()
asyncio.run(hello("ws://localhost:8765"))
And here’s an echo server:
#!/usr/bin/env python
import asyncio
from websockets import serve
async def echo(websocket, path):
async for message in websocket:
await websocket.send(message)
async def main():
async with serve(echo, "localhost", 8765):
await asyncio.Future() # run forever
asyncio.run(main())
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 usage 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.7.
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-10.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5880442f5fc268f1ef6d37b2c152c114deccca73f48e3a8c48004d2f16f4567 |
|
MD5 | f4576a80f69b60a8e1ebc386aac50ad0 |
|
BLAKE2b-256 | 34d25c369a9e8c9a1dd6d6eea2776c01888cdec57244935b78d9b88ca959ae13 |
Hashes for websockets-10.0-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e42a1f1e03437b017af341e9bbfdc09252cd48ef32a8c3c3ead769eab3b17368 |
|
MD5 | 70fde94e5c4fa5ddd8933fdcf711d47c |
|
BLAKE2b-256 | 86521c4c68b544ad4c44146219b48f4782e9d5ba8f1f22c545b7fb5b520b751d |
Hashes for websockets-10.0-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62160772314920397f9d219147f958b33fa27a12c662d4455c9ccbba9a07e474 |
|
MD5 | 68cb0c4218040fecb0f869b6aab1e5c7 |
|
BLAKE2b-256 | d721abb4107b1d8fd16be7da07c58dc600f66b05419bd3e5c84ca660d686fc47 |
Hashes for websockets-10.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb282127e9c136f860c6068a4fba5756eb25e755baffb5940b6f1eae071928b2 |
|
MD5 | 8aefe981fc4e61af4adeea6edba97786 |
|
BLAKE2b-256 | 9dbaa9f4a162a0cdb1896086b3643952b15cfdf2366f3cb0e59730ccc35f72a9 |
Hashes for websockets-10.0-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe83b3ec9ef34063d86dfe1029160a85f24a5a94271036e5714a57acfdd089a1 |
|
MD5 | 738701b4965d30430e8a089c17b56e6d |
|
BLAKE2b-256 | d6c126d7e3415abb00f339bb97960e508fe15cd504ea0b1f69727833abbc2a07 |
Hashes for websockets-10.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71358c7816e2762f3e4af3adf0040f268e219f5a38cb3487a9d0fc2e554fef6a |
|
MD5 | 48d995b3fc20f3d607f9821758a1cf0d |
|
BLAKE2b-256 | bf221215e2eb6736855292daeb145acea0061a4572901b23f50c8678603e996c |
Hashes for websockets-10.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d2e12e4f901f1bc062dfdf91831712c4106ed18a9a4cdb65e2e5f502124ca37 |
|
MD5 | 4d77eeb2b35fdd95f025822403c9dd07 |
|
BLAKE2b-256 | af0228775bbb4ae7a9a15f190360b4844a7f6e832b50d99baaba4d78f97d4573 |
Hashes for websockets-10.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82bd921885231f4a30d9bc550552495b3fc36b1235add6d374e7c65c3babd805 |
|
MD5 | ece184b2b3075a2f34c58e85bd76ffd4 |
|
BLAKE2b-256 | c50c84492bdc040734b55d06c5f107019efae96124ce95355861cc1edcf82695 |
Hashes for websockets-10.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d67646ddd17a86117ae21c27005d83c1895c0cef5d7be548b7549646372f868a |
|
MD5 | 08f841d5dcb8c7075e0dd1ee7a408f68 |
|
BLAKE2b-256 | 34e345787d73e93ece933f39efef394f23e59b027292883acdf1fd46c9f9d8db |
Hashes for websockets-10.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff59c6bdb87b31f7e2d596f09353d5a38c8c8ff571b0e2238e8ee2d55ad68465 |
|
MD5 | a5f667f47016fe1105f138882fe40d99 |
|
BLAKE2b-256 | f058bb72c925ab91169c556bd098eb9cc4d381966ddc688684f88c9aa382e3d2 |
Hashes for websockets-10.0-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ac35426fe3e7d3d0fac3d63c8965c76ed67a8fd713937be072bf0ce22808539 |
|
MD5 | 50c36c1cea7ebf3e385b83979925b554 |
|
BLAKE2b-256 | 60eeec5f5adf6831ce6b334e72a50783041cfc776e7a187c44309fda3b46e8ee |
Hashes for websockets-10.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f79f02c7f9a8320aff7d3321cd1c7e3a7dbc15d922ac996cca827301ee75238 |
|
MD5 | fcb46b809cc7696cb4e2ecc0bf7e25d7 |
|
BLAKE2b-256 | bacf5cb32e1ddb75d13be4c5bfe1b1165a3be4ea0d854816ad3ccf2c5e336c1e |
Hashes for websockets-10.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a43072e434c041a99f2e1eb9b692df0232a38c37c61d00e9f24db79474329e4 |
|
MD5 | 151504e9c3e3de420cbc3a557ebbee36 |
|
BLAKE2b-256 | 759c55de923a47ee0816fb0c6e1b343d56a904f3ea52948631b043fbd5a1cf2b |
Hashes for websockets-10.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4ade7569b6fd17912452f9c3757d96f8e4044016b6d22b3b8391e641ca50456 |
|
MD5 | c9639ac04f223c1c47bd31d18cb7290c |
|
BLAKE2b-256 | be0710af69973f1b609b689dbfa14c7c7f7ff20c74eb4ff5eec7125c4d8c7d8f |
Hashes for websockets-10.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a4d889162bd48588e80950e07fa5e039eee9deb76a58092e8c3ece96d7ef537 |
|
MD5 | eaa29421690b74a59ebd749e8929f0a9 |
|
BLAKE2b-256 | cd9e97bd5683a3d21da8574b7261aab1809a6f438f776620e7892f09aa032d82 |
Hashes for websockets-10.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 085bb8a6e780d30eaa1ba48ac7f3a6707f925edea787cfb761ce5a39e77ac09b |
|
MD5 | 0b4cc5e91eafe4949b594042023da281 |
|
BLAKE2b-256 | c7b4be92fc41953ef3087470b7f0ae99295b8d82b6c5b998b749109fc1ac5e75 |
Hashes for websockets-10.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b2600e01c7ca6f840c42c747ffbe0254f319594ed108db847eb3d75f4aacb80 |
|
MD5 | 1d89f1ee057896e9e182103e648df408 |
|
BLAKE2b-256 | 696b0795a73cecee94f562eed4eacf26b7f650fd284a001dcf16a3b12a7f7a9a |
Hashes for websockets-10.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 706e200fc7f03bed99ad0574cd1ea8b0951477dd18cc978ccb190683c69dba76 |
|
MD5 | 0898f32e697d65849c5e16884a24ec92 |
|
BLAKE2b-256 | 90420241ddd26a34fb7db0b51a4d41a51ed5f40181471389d63254026d79ca2b |
Hashes for websockets-10.0-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8176deb6be540a46695960a765a77c28ac8b2e3ef2ec95d50a4f5df901edb1c |
|
MD5 | 1a5c403117958d3cfa18e8f45478f9c7 |
|
BLAKE2b-256 | 7f2af78460d15487fccedec68660d6f28ef939c099e9768f291b8aa75607d60d |
Hashes for websockets-10.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bbf8660c3f833ddc8b1afab90213f2e672a9ddac6eecb3cde968e6b2807c1c7 |
|
MD5 | f4b88c7986d7ba07420884dd88140732 |
|
BLAKE2b-256 | 3d80f1ee17ec318b07803ae21b6e3c7c3c7a611ae3288576d33d877d819c74f7 |
Hashes for websockets-10.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82b17524b1ce6ae7f7dd93e4d18e9b9474071e28b65dbf1dfe9b5767778db379 |
|
MD5 | 54ec5e075a157d87fcade374b60a56a2 |
|
BLAKE2b-256 | 33885d8c4de479140b73354c30af02947315b29848dc62f0c3c7dadfb5d0d01d |
Hashes for websockets-10.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01db0ecd1a0ca6702d02a5ed40413e18b7d22f94afb3bbe0d323bac86c42c1c8 |
|
MD5 | 03919267ebeee274def6350079fd1ef0 |
|
BLAKE2b-256 | 5ccd94b3f161df0d4e7ffca58f45cd21dd2701ae49ea1eed0aa3123314edaab2 |
Hashes for websockets-10.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f6b814cff6aadc4288297cb3a248614829c6e4ff5556593c44a115e9dd49939 |
|
MD5 | 1143fda7daa886efbd0afcc4f5a88dfe |
|
BLAKE2b-256 | 9a73ba1ceeaff36705c14f36564001c0de142ce0d909a599e9169cb95640e180 |
Hashes for websockets-10.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd8c6f2ec24aedace251017bc7a414525171d4e6578f914acab9349362def4da |
|
MD5 | 6cc776217d74184f94b62400077bef8c |
|
BLAKE2b-256 | ae50a3655e01f90fb048361c951b421f057aca932d56b07b43464f324254d003 |