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.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85db8090ba94e22d964498a47fdd933b8875a1add6ebc514c7ac8703eb97bbf0 |
|
MD5 | b023dd719bb4e3f6dd2ccb0596907596 |
|
BLAKE2b-256 | d7d7cd60ce74675402998e285f9f54baf86c80daaa473e557c92f53c01b10f2b |
Hashes for websockets-9.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be5fd35e99970518547edc906efab29afd392319f020c3c58b0e1a158e16ed20 |
|
MD5 | 95633174bf64994314161fe8f48aae3e |
|
BLAKE2b-256 | d6c98d3e0904e624b1b83f1939170ed28002c971dcf960093eb2154af8408b67 |
Hashes for websockets-9.1-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebf459a1c069f9866d8569439c06193c586e72c9330db1390af7c6a0a32c4afd |
|
MD5 | eca4e2029f910d3e3358387e9053c93a |
|
BLAKE2b-256 | 219b112c8439c718432fd3fb1f6fa56050767a70ad977712008cec036d061a7a |
Hashes for websockets-9.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d6b4fddb12ab9adf87b843cd4316c4bd602db8d5efd2fb83147f0458fe85135 |
|
MD5 | eac88c338dd93608fc6fb3e3e6a5c583 |
|
BLAKE2b-256 | c831bb59de44c04c5d81083a5ee93eeb3e9b30d32aa8f6b72080eb5da4bb73f7 |
Hashes for websockets-9.1-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad893d889bc700a5835e0a95a3e4f2c39e91577ab232a3dc03c262a0f8fc4b5c |
|
MD5 | c9850c3cbb502a9057fde3d06c88bd84 |
|
BLAKE2b-256 | 189c3334655fd3eb93fe3b728203db354711cec48044c2d7b8bfbde9ea0ffc5d |
Hashes for websockets-9.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 597c28f3aa7a09e8c070a86b03107094ee5cdafcc0d55f2f2eac92faac8dc67d |
|
MD5 | d15fd8677a24a19249eb9320f60f07c9 |
|
BLAKE2b-256 | 96d03e5beec93673fc4526e118f45e56df8a292b6f009002675614f4e3dfcf3a |
Hashes for websockets-9.1-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e7fdc775fe7403dbd8bc883ba59576a6232eac96dacb56512daacf7af5d618d |
|
MD5 | 9f72ed748c0dbd1829f50505bb0a2f1f |
|
BLAKE2b-256 | 46e7ebbe5d8ce59c77b59a13551fe0103c73131fab0b7cfb2fdc10b58f252e13 |
Hashes for websockets-9.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e5fd6dbdf95d99bc03732ded1fc8ef22ebbc05999ac7e0c7bf57fe6e4e5ae2 |
|
MD5 | 616489d0c0c902fd5431539641f7c47f |
|
BLAKE2b-256 | e5b30ff0676cb0043bc85f4cb548733a37b5e7e9b82fe253edd0f5d173b2ec43 |
Hashes for websockets-9.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7189e51955f9268b2bdd6cc537e0faa06f8fffda7fb386e5922c6391de51b077 |
|
MD5 | 8f0f5457c6fa7d52197a941f37c12c63 |
|
BLAKE2b-256 | f9681e4a45c29466edbe4247917b22b8ced34a8b6766194cac84b860c9262039 |
Hashes for websockets-9.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d0971cc7251aeff955aa742ec541ee8aaea4bb2ebf0245748fbec62f744a37e |
|
MD5 | 0539dae074809b2e1233b338bf92c100 |
|
BLAKE2b-256 | 7d79c1dc497c3b7edfcc39d8ea759da883d5e4fa80270c2c14ee2bab00cd1b46 |
Hashes for websockets-9.1-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dd4eb8e0bbf365d6f652711ce21b8fd2b596f873d32aabb0fbb53ec604418cc |
|
MD5 | 5349723a22ecaca0423d8786e10dde1f |
|
BLAKE2b-256 | 0c081b50891a5101d71e7b739085b425aefcafd06ec37116d8fff2381776d0e8 |
Hashes for websockets-9.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 826ccf85d4514609219725ba4a7abd569228c2c9f1968e8be05be366f68291ec |
|
MD5 | 74ff98d70a2710d163d4413c54b73ed6 |
|
BLAKE2b-256 | aa09bd9b3057ec5cd7743066c84ade52ff99eb73059f7d33d810d79dc4534ae1 |
Hashes for websockets-9.1-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7df3596838b2a0c07c6f6d67752c53859a54993d4f062689fdf547cb56d0f84f |
|
MD5 | c76171b241cc379bcf55bc7c2e232735 |
|
BLAKE2b-256 | b764e071c72bcb02e4bb82b1eca05f8d3b4b800580b140491138720c07ffd582 |
Hashes for websockets-9.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 230a3506df6b5f446fed2398e58dcaafdff12d67fe1397dff196411a9e820d02 |
|
MD5 | fcd4ae8b2f3c4e81c7a4a596164c35b9 |
|
BLAKE2b-256 | d9fbc2111a59e4fdcb09a2a088f8bf5832274ef84930b67ab20592b3f2c1ba75 |
Hashes for websockets-9.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2e71c4670ebe1067fa8632f0d081e47254ee2d3d409de54168b43b0ba9147e0 |
|
MD5 | 3d87fe0ba6fead6377e1e750126b577b |
|
BLAKE2b-256 | 31ff2dd99b27bc6c644abad06033103ced832e8983be161091f8cc8d2d15adb1 |
Hashes for websockets-9.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85e701a6c316b7067f1e8675c638036a796fe5116783a4c932e7eb8e305a3ffe |
|
MD5 | 5446de592d0265245dc3853335dd557e |
|
BLAKE2b-256 | e96999cad51d5aff90eb804eb98f588d03c9c1070d71c5c82f23142bc081af51 |
Hashes for websockets-9.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab5ee15d3462198c794c49ccd31773d8a2b8c17d622aa184f669d2b98c2f0857 |
|
MD5 | 21b836f25684c9d4a371ca253557c312 |
|
BLAKE2b-256 | 103f85b54ffa6fb2b622c27a32ece61672fbcc39fcb69e51ffb1e740018b5773 |
Hashes for websockets-9.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 900589e19200be76dd7cbaa95e9771605b5ce3f62512d039fb3bc5da9014912a |
|
MD5 | 7764629107c85b59ef948f1df5ce8243 |
|
BLAKE2b-256 | 2cb5c1181f7dce9d3e894d794227fa7df268c52f9746492362482a9ede941b62 |
Hashes for websockets-9.1-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48c222feb3ced18f3dc61168ca18952a22fb88e5eb8902d2bf1b50faefdc34a2 |
|
MD5 | 8b05d2192bda833e06db91bf1a60bef9 |
|
BLAKE2b-256 | c9597856d7557e8a538a8c6006b81bc0e4ffe6d5687c3e9c685ebfeb3317a2f4 |
Hashes for websockets-9.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 836d14eb53b500fd92bd5db2fc5894f7c72b634f9c2a28f546f75967503d8e25 |
|
MD5 | 9b05aeedf9825dc1a192c3beefeba157 |
|
BLAKE2b-256 | 846478c2b3fe37730b30dca3c93d1f7f4a4286767f86e7c04cf3571b39bc2fb7 |
Hashes for websockets-9.1-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9147868bb0cc01e6846606cd65cbf9c58598f187b96d14dd1ca17338b08793bb |
|
MD5 | ab836545b67a8ceda6a10c1254018c54 |
|
BLAKE2b-256 | e7e7629ce181250f6a0d7415acee6597cc010ba02b81e17954156fd9942aed9d |
Hashes for websockets-9.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b43b13e5622c5a53ab12f3272e6f42f1ce37cd5b6684b2676cb365403295cd40 |
|
MD5 | 7cbc6e7eb5e70c44f3d23a1113fc0fb3 |
|
BLAKE2b-256 | 3bbd6f63619fecddef9c411e0390274194f46f7596ae69945c1fd0a1f8caaf4a |
Hashes for websockets-9.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f68c352a68e5fdf1e97288d5cec9296664c590c25932a8476224124aaf90dbcd |
|
MD5 | 9363fc72767805629990f2986b9e8bf3 |
|
BLAKE2b-256 | 50de3ab2775e26eb6c76b7a7771903e6aa7645a16024173ba5b0d56deb970f9d |
Hashes for websockets-9.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51d04df04ed9d08077d10ccbe21e6805791b78eac49d16d30a1f1fe2e44ba0af |
|
MD5 | 3a76d58ea93db3c3804582804f254930 |
|
BLAKE2b-256 | 58097dcd264c9db98d09799936e801ba4c2ddfd1eac8f3eb05e14b3091bd72e8 |
Hashes for websockets-9.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ddff38894c7857c476feb3538dd847514379d6dc844961dc99f04b0384b1b1b |
|
MD5 | bedc944cf01c051c78957fa2d41ff007 |
|
BLAKE2b-256 | 71bb6048f839ff53a79fd81941882bdbfd6ed88e5cd36bd6ba796b4ec309a47f |
Hashes for websockets-9.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f31722f1c033c198aa4a39a01905951c00bd1c74f922e8afc1b1c62adbcdd56a |
|
MD5 | 7cb59dd02850608022c446f91811da43 |
|
BLAKE2b-256 | c3a4d6b46ae672875d1b150c818fc7381b591d4809904e5a5d7de0f603f177b5 |
Hashes for websockets-9.1-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2c2d9b24d3c65b5a02cac12cbb4e4194e590314519ed49db2f67ef561c3cf58 |
|
MD5 | a33989815b6b02ce0391a8625e00bc3a |
|
BLAKE2b-256 | 184e25edfeb19f2d518df137220e107aacf6b17da45fa943f6a7f45d326060f8 |
Hashes for websockets-9.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caa68c95bc1776d3521f81eeb4d5b9438be92514ec2a79fececda814099c8314 |
|
MD5 | 98b832c2ebc76d206fe32a26dbb2f29a |
|
BLAKE2b-256 | d9a438eb0bc75fb6ea61dc54d5131286d1f474abc83de89cb6e217fb9e244570 |
Hashes for websockets-9.1-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c8f0d82ea2468282e08b0cf5307f3ad022290ed50c45d5cb7767957ca782880 |
|
MD5 | 4aeafea4d2cf89e222be9898f6ae50a0 |
|
BLAKE2b-256 | 2febf007b79056fdbc9b4c0b3d06c4580c4270ec3fe8438cd8acd6d682ab8383 |
Hashes for websockets-9.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cf04601633a4ec176b9cc3d3e73789c037641001dbfaf7c411f89cd3e04fcaf |
|
MD5 | a076d7714c5eb1f2779c085e17599ab1 |
|
BLAKE2b-256 | de828ea9bc17518d6a3e14941b857339e502dfba7c6ef81942caebb7463c85c3 |
Hashes for websockets-9.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4ad84b156cf50529b8ac5cc1638c2cf8680490e3fccb6121316c8c02620a2e4 |
|
MD5 | 608d6bf7639da3c5b7a689d378cc6b9a |
|
BLAKE2b-256 | b2bf9b2903cc82c474c33fd9cb9b23507535b9c7562ee4ab007f3ca6665b91dd |
Hashes for websockets-9.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d144b350045c53c8ff09aa1cfa955012dd32f00c7e0862c199edcabb1a8b32da |
|
MD5 | 39d81d9c964f94cd1ce5c6c8415c1587 |
|
BLAKE2b-256 | b2a01cc1c0994aab526fde1a57f31db8069ae9e31f25866294d889c2c8d71975 |