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.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73a9195c6e009d0c34d0519eb75c5d78e5bd0d2e3998f35b0c35e1e23b3f5a6b |
|
MD5 | 58039830062fc361ca479eb0d6527fd6 |
|
BLAKE2b-256 | 65c03bdaad1cab3152f68857868df93d582ee0e6fc8693333effa419fc334eed |
Hashes for websockets-9.0.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c0a414ffebb1cd5fc603cc1cb5347f5e564762aa8f12c411507c7345907781f |
|
MD5 | 2a12e6f90ddf12cdc89aea459f39fe86 |
|
BLAKE2b-256 | 84933c962a0d3ac96250670ffad9adc3733ad05a5d1dd023e4faef2f7e5516f6 |
Hashes for websockets-9.0.1-cp39-cp39-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a508a1e2630ebd88c4a60e0443a4bc3b6370d2a9c2c2d534ab0d718cd63ad589 |
|
MD5 | be37113c9513a7e4a75c3544028b225a |
|
BLAKE2b-256 | 074b9a94869efbf77b25fdae834d926802d33e906f22e2c112acac6d364ae69d |
Hashes for websockets-9.0.1-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a69e07ed385b383adc0731effe47680caa60232cb32bf43e38dd1e48c602126 |
|
MD5 | b24504554be11317aabab0f8ec156136 |
|
BLAKE2b-256 | bfdad4e168560d7214181122db23bff50eecf750f3de6b67e543feb90333c273 |
Hashes for websockets-9.0.1-cp39-cp39-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a1f7580a035e97d015963c6935d5ba9aabca8fca056aaef73e82d3bcfee6d79 |
|
MD5 | 0203cb87847cf9b7b31af933efe90862 |
|
BLAKE2b-256 | f403748b966850425542b03061f13ff557c34a36a90b5450ea6136da34736192 |
Hashes for websockets-9.0.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 407a215d4d92576b582dac3bb8a66e0d7d1428abb1c48b2c0cf7e8e71c87e2f1 |
|
MD5 | 383fac0761f8b9e9225d9eae6c6adce9 |
|
BLAKE2b-256 | c61b7a5e1884c6782aa29b35b441f0a57368647caeec49713708befc51606520 |
Hashes for websockets-9.0.1-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60ecbc6ce686dc1d640d9771342e3f4477f21fa65a10235b390c45c28b3c2399 |
|
MD5 | 5bdafb4c2e4e563b1bc052aade8b1d1e |
|
BLAKE2b-256 | db75b55c84b72208f2c677681bb2938cb5d50b48ab8b59801aee9e0557d218d0 |
Hashes for websockets-9.0.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b15043e495ff7a601a98d4d5f019f1ae4b6b643d9dbcf3d9398af58fe5545148 |
|
MD5 | cdb769bb9342e4404cf513532b9cdf86 |
|
BLAKE2b-256 | 0a6dc2b8bf084af19b37d8ea3ab85811fdd70735579f78fc8e93b40b8a39bde5 |
Hashes for websockets-9.0.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0943a856b38ecafc5ab96261687d1e744d4307815927911eb76ae609b5d21e0e |
|
MD5 | 72b9a0c4beaa9f697655139c53d7b4a5 |
|
BLAKE2b-256 | 825e267b130193dcb862649ff2ce9ce4f337fa26ba0c1b9f83b405f5b08b2e64 |
Hashes for websockets-9.0.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3437fd1fce7a40fa315080ab61c7744695a2ca3e8d5d6e7576d09c4b697b7f38 |
|
MD5 | de22496c891eca665be8025b0366f9e7 |
|
BLAKE2b-256 | 1a2adcbd185b58e3975ba98e810e9a8a3bc14760f6e0b2839520f74a7be22baf |
Hashes for websockets-9.0.1-cp38-cp38-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b61adeb0bc4b34a62ec231b320967d7ca61b40ee26f8ec8d93d1d5ae292deef |
|
MD5 | b774f8f5431ea46dad615f749da98bdc |
|
BLAKE2b-256 | 44b557f4bcab49f0c279a820d427fb6386038fdf5cee7db65440fdcd139e024c |
Hashes for websockets-9.0.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b5c20681b1e12df80499e3323e3cdb2b813553e2553aa392d3db8a063100fb8 |
|
MD5 | 0223ece307049a1f0b1885e9508a12e0 |
|
BLAKE2b-256 | f8a6ede5b4478feabf819ab17dea6408b6d54d7373ca03752412c1b33ffaf4f1 |
Hashes for websockets-9.0.1-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a73c4f9d0a5796688753c115b3b5a29269e0bcb8661f5d0f9e1352b81839fd |
|
MD5 | 27ea9b8b023ace5df9dcd1da0e3fd3d1 |
|
BLAKE2b-256 | 422ec47df81e05d9b7c66c1770a0850eb70ee56de084b756e75e71cc141eec0f |
Hashes for websockets-9.0.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 163c6cfdf74e2034b22c51c727b7f7b4aae2fa949555aeafd79dcffab34b2bd3 |
|
MD5 | c92d63cb329b2ebc86d968cdabf02b25 |
|
BLAKE2b-256 | 57c1f0db4d7fbaeee817f5ccd24e8ffc59bcc74f71a48e1e67562f6d8b324911 |
Hashes for websockets-9.0.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f876ae0e6acfcce6cd03601f9bda37f210b568888cba99075f64503bf2174a08 |
|
MD5 | 8c5960f83baf7e9b1de54cd087f4e516 |
|
BLAKE2b-256 | 3831d741c6f1f0cacb425213dd3eb6c0e417b7bca7be372fa21b3002d498e47e |
Hashes for websockets-9.0.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e496386bfb8e1e89824bb488f387bca8eff304c67fd030f1bd40d0c41a8f8734 |
|
MD5 | 219ffc2c65f4eceb928b6b150b016a04 |
|
BLAKE2b-256 | 1ee2ce2d2f7d0de42ce161ec05e253880edc1fed2e1cf7080727aa46257a4840 |
Hashes for websockets-9.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cf7b0b78ed8134c6043d6425d53ee1232de1d07e4df02d446e4d0bff93270c1 |
|
MD5 | 0568f5cf69edb0a88e53737af3f8f333 |
|
BLAKE2b-256 | a8296b5fd6efdb4bf2cde94a28ebd2fa9a5cecd5d8b66f9017ef8f012f30e416 |
Hashes for websockets-9.0.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55299ba19717d6cfc5341d1653d2ada41986073978bf1f6128cdf0fd4bc240c1 |
|
MD5 | 2a4100f0e4438b6e2af09cfa54339e27 |
|
BLAKE2b-256 | 7fdfc8dd8c57f4ba462bb4365ca06a910916ae7326a631d3e43cce4bdd4821df |
Hashes for websockets-9.0.1-cp37-cp37m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a864ecd9e3a862342b6288129cd0557e2d0a785ec82ded4b562254e326e5a566 |
|
MD5 | 3c9743927cc212e00ab4ed7d6dde6018 |
|
BLAKE2b-256 | c8a14393002e8bc02457166ba971a6f55e6c966348413a32471c127b4a209a4c |
Hashes for websockets-9.0.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f768eeaa001efc23d140701e666b18f76b9aaaefc38889bdb3a47afabdbd199 |
|
MD5 | d0deae640e6f8cee6c024b69daeaf9f1 |
|
BLAKE2b-256 | 73cb1d313fca7318f87cd7edfeb82339c20f00f24457862ba6fb455915fb8d9f |
Hashes for websockets-9.0.1-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d084ac3da927dd252fe11cb082a75dbb377fbb11e8ebdc095297ef44d0764aa |
|
MD5 | 03ab89b613eed6e87bbddb9c3d6dceb2 |
|
BLAKE2b-256 | f9baa641e5e3659c14d828bf9fc13993e2ef20110246a4d7be3b0070182555bd |
Hashes for websockets-9.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9480bb6f41f76de3fd7a8937834f740fd331a3af2d92dd15d45a2c27c6b546e6 |
|
MD5 | 8534339bb424724aa39c2c2937b45d60 |
|
BLAKE2b-256 | 9e5ff7447c27922c555e8b498cd0091f028ae49ec419b77c7765c5eabf534971 |
Hashes for websockets-9.0.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66c112ef31a8b419dac4a1a5baaa2e76610ed184801123e80a0ba9c7173177ff |
|
MD5 | 5f934bb0b6352b4ce3a559022b9adf35 |
|
BLAKE2b-256 | f1816ed5d03af2c918574d25461f9b314d5db56e842968076b6c57fa93ecd86a |
Hashes for websockets-9.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b0ac168c258c6e42cabfef699c1282043e9fa0e7d6a211f93998dc8b2249238 |
|
MD5 | b9e7e0d9e74faab326636f0afa047a9e |
|
BLAKE2b-256 | b348ddba040ffc863bd797c81fe0b126a0dd990241460082e8c0e8d223a78b93 |
Hashes for websockets-9.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16c1875f957c685e8bd815cd164eaf46373940c14b01b0baff81169249c95922 |
|
MD5 | 08aae393e00871ca296f6becc4cb7d3d |
|
BLAKE2b-256 | 5a6ab78414c3be82330d7909b750b8ab6a06c05481a721e00eb18b466fd7d8a7 |
Hashes for websockets-9.0.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a96ed836dae26d50ef69648ac804c7e53aca81dd9c90ef1128acef3925b7e055 |
|
MD5 | 4b176d19ba1d00d094f41b4c07ead2ad |
|
BLAKE2b-256 | 16d0534c8575c3068d84f28f52ab24748a917f031c722f9b9335400b9c731331 |
Hashes for websockets-9.0.1-cp36-cp36m-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccce35e8ab229a5b518bc72391ea5989fb6fec9817e772897d67ff1a12cc1a8b |
|
MD5 | c9eb6b92c04efc6f69a578a309a4b021 |
|
BLAKE2b-256 | 2fa704300f9714620327fa95be0a0a78973147097caa29c33c8b9204b1d807f4 |
Hashes for websockets-9.0.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 966fe1574708927322d0b5caff0b49fd7ab5f889eb4ba6aefa5718be3e7c879f |
|
MD5 | 92f58cf5a23be406bbd2f8cea2c8026b |
|
BLAKE2b-256 | 639a2b94d9b88926debfaff4ce4b83abfad754b4bd48bb1417698dd9f55edc16 |
Hashes for websockets-9.0.1-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cfbe5339dc5a2dc813e96626fa9e659e252df78fbef5b8e67ad17578a78c147 |
|
MD5 | fef5464446dfe5580100d6517ed436fc |
|
BLAKE2b-256 | 07decfd54bcf47ff869aa4a5b150137d8a299535e495a95f1910f466e6df2ce4 |
Hashes for websockets-9.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77866cba716a78a056612541f9cc47de93ba70cee3395337131cd3cb87a10273 |
|
MD5 | e17487c09d1a0328bae5417e5487c9c2 |
|
BLAKE2b-256 | ab1f310403e6baa3eff05abf6a5fb582c3c1d4372574254818f827356dc05abc |
Hashes for websockets-9.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33c59a9151bd0b133e6314063f5a5924273e6ff038e7ac9ec7dcea40d0619723 |
|
MD5 | ded7bd4abb936c384d373d4794a0acf6 |
|
BLAKE2b-256 | 39696fa2a8a00f4eba17dcdddf41f0f92db01d49de33a3eedfb8c2035fe1e75a |
Hashes for websockets-9.0.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69a5972956759224c5201007ff49398a78a23baca344185533093602f56cbbbe |
|
MD5 | c1d34a4e3aa2c70afc34e48751fd6f4b |
|
BLAKE2b-256 | 2542b0cc530abb91ef75c8704fcfb0ba0bc043d4de1253d9e4738197f6575e6f |