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-8.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8a7bff6e8664afc4e6c28b983845c5bc14965030e3fb98789734d416af77c4b |
|
MD5 | 3e694f97aaf4386719186b1171c213c6 |
|
BLAKE2b-256 | 36825797b2760cbbcfef28eb9060c6469c447f77e34c95e6ded7833655011fc7 |
Hashes for websockets-8.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e898a0863421650f0bebac8ba40840fc02258ef4714cb7e1fd76b6a6354bda36 |
|
MD5 | f639824b83bfb71bde17e82c36459d9d |
|
BLAKE2b-256 | 3cb9be61f1c129fcef9f54036d9b230ff5daf88a5557cc3193339e2806226093 |
Hashes for websockets-8.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8a116feafdb1f84607cb3b14aa1418424ae71fee131642fc568d21423b51824 |
|
MD5 | 45c0c7fc8f3705a2d68b94cd73f8e74b |
|
BLAKE2b-256 | 1f5f61cbb8d89806e82d2dc8824c48d7a696bd89a95acf8f88e3e4bdcf0a4abe |
Hashes for websockets-8.1-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d705f8aeecdf3262379644e4b55107a3b55860eb812b673b28d0fbc347a60c55 |
|
MD5 | 794feedb1187de6807708129de2fd377 |
|
BLAKE2b-256 | 695f9e880495118332a3ee8babd205d99e402dd5d1634279f245fd8e5daa5aab |
Hashes for websockets-8.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bef37ee224e104a413f0780e29adb3e514a5b698aabe0d969a6ba426b8435d1 |
|
MD5 | 8f33f6c76bbc1a05bbd7bb4f2ef4cbc0 |
|
BLAKE2b-256 | a9289aeaac68c2efc83f09f62ac067fb696f628e0856925e754625dedf3de73a |
Hashes for websockets-8.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c01fd846263a75bc8a2b9542606927cfad57e7282965d96b93c387622487485 |
|
MD5 | d117e74a879ba1ae8f35bd7c3534e313 |
|
BLAKE2b-256 | cb8c96cf90123ab16c4b50c62f9e22b77e712c838cf16df57b7f04465110666a |
Hashes for websockets-8.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1ec8db4fac31850286b7cd3b9c0e1b944204668b8eb721674916d4e28744092 |
|
MD5 | 87913cd8152aefc4ef38397dcb9ac8b1 |
|
BLAKE2b-256 | d8e19897d72c461388834f4e0ecf5c4e91a31f157aaebdd7e8eb5dfb73481acc |
Hashes for websockets-8.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20891f0dddade307ffddf593c733a3fdb6b83e6f9eef85908113e628fa5a8308 |
|
MD5 | 9c96dfab99cbb424f3041ecf6009ed6f |
|
BLAKE2b-256 | 56011f61610f1eb7f9a8e8fdc607a89dd2fae778e6e43290d7e153ebe724adb5 |
Hashes for websockets-8.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ff46d441db78241f4c6c27b3868c9ae71473fe03341340d2dfdbe8d79310acc |
|
MD5 | 6d9edd7fc089cecb63a762d7f5b2ce8d |
|
BLAKE2b-256 | 2c46124b39247a67b0650ecff6cf4cceaeba2874e9458ad49e1570713d2c386d |
Hashes for websockets-8.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ef56fcc7b1ff90de46ccd5a687bbd13a3180132268c4254fc0fa44ecf4fc422 |
|
MD5 | db78af319167c89484a27dd339463aac |
|
BLAKE2b-256 | 5a0b3ebc752392a368af14dd24ee041683416ac6d2463eead94b311b11e41c82 |
Hashes for websockets-8.1-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 751a556205d8245ff94aeef23546a1113b1dd4f6e4d102ded66c39b99c2ce6c8 |
|
MD5 | 461724607cbcebdb128ec8f7ef45784b |
|
BLAKE2b-256 | e61d7b9c4681c64d092fc0f156e018074abf349f6b19f364da84181197add393 |
Hashes for websockets-8.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 965889d9f0e2a75edd81a07592d0ced54daa5b0785f57dc429c378edbcffe779 |
|
MD5 | a5c4a171f8fab009c795a7c9bb0c3b64 |
|
BLAKE2b-256 | df192573653fb823929324667c936541be610869b2b389eb9dabfe8c874ea80f |
Hashes for websockets-8.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce85b06a10fc65e6143518b96d3dca27b081a740bae261c2fb20375801a9d56d |
|
MD5 | 40e252d118705fd148849765604ad713 |
|
BLAKE2b-256 | abedf2da446105d84b20395806a73b7567af7b840685153741a72f6674dc0ab6 |
Hashes for websockets-8.1-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b248ba3dd8a03b1a10b19efe7d4f7fa41d158fdaa95e2cf65af5a7b95a4f989 |
|
MD5 | 1c2acf27b7abb12d3e83b9866c1d7853 |
|
BLAKE2b-256 | d4c26d7eaf91c81328c31b9d98fe97df3fa657b2d7d2610d8a14fc27ec48dafc |
Hashes for websockets-8.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e4fb4de42701340bd2353bb2eee45314651caa6ccee80dbd5f5d5978888fed5 |
|
MD5 | 207ffbeedfedcd3ef20aa7b03d422cf5 |
|
BLAKE2b-256 | 78489e5bb47b0c26bf02ffcff691a0ef0b1b1ef7824e9b240bad3f494a886897 |
Hashes for websockets-8.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2db62a9142e88535038a6bcfea70ef9447696ea77891aebb730a333a51ed559a |
|
MD5 | 1005cad8e9b06b6539fc7a4119b8bf86 |
|
BLAKE2b-256 | 1ca7b2c2057ecb1fb8ad48361735be4760009d27753d129cc9d22c1dc6bb42ae |
Hashes for websockets-8.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d3f1bf059d04a4e0eb4985a887d49195e15ebabc42364f4eb564b1d065793f5 |
|
MD5 | f611ff571d60ef083c87f6530d0808bd |
|
BLAKE2b-256 | bbd9856af84843912e2853b1b6e898ac8b802989fcf9ecf8e8445a1da263bf3b |
Hashes for websockets-8.1-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 295359a2cc78736737dd88c343cd0747546b2174b5e1adc223824bcaf3e164cb |
|
MD5 | b89d57dc6f563d977dccadcd933b2f3e |
|
BLAKE2b-256 | 72536c1480bc5dc19a586880b6c37b8d19b1c89824797f59021f6af1d652cdc9 |
Hashes for websockets-8.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f9f7d28ce1d8f1295717c2c25b732c2bc0645db3215cf757551c392177d7cb8 |
|
MD5 | 4b314e9eaafefd36f650102c59578aba |
|
BLAKE2b-256 | cfcbc35513c4a0ff24ca13e33f7336ba8c1a864449fad9fea8e37abdad11c38d |
Hashes for websockets-8.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3db87421956f1b0779a7564915875ba774295cc86e81bc671631379371af1170 |
|
MD5 | cd63d2c2c7e82b3a036d720f3bf6c49a |
|
BLAKE2b-256 | c834947fff38511d40daa350f63a1b1a972767c90a30c0f6115a622642b48a4d |
Hashes for websockets-8.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3762791ab8b38948f0c4d281c8b2ddfa99b7e510e46bd8dfa942a5fff621068c |
|
MD5 | a0d718ed722514af6b13749344ba5018 |
|
BLAKE2b-256 | 1bd0df088c0bcb09efdf643f26df5ba3e40bb7e79cae34b3fa48d547da658c5c |