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.
Here’s a client that says “Hello world!”:
#!/usr/bin/env python
import asyncio
import websockets
async def hello(uri):
async with websockets.connect(uri) as websocket:
await websocket.send("Hello world!")
asyncio.get_event_loop().run_until_complete(
hello('ws://localhost:8765'))
And here’s an echo server (for Python ≥ 3.6):
#!/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? Start here.
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.
Professional support is available if you — or your company — are so inclined. Get in touch.
(If you contribute to websockets and would like to become an official support provider, let me know.)
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.4.
What else?
Bug reports, patches and suggestions welcome! Just open an issue or send a pull request.
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-6.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0873eadc4b8ca93e2e848d490809e0123eea154aa44ecd0109c4d0171869584 |
|
MD5 | c8ce26cfa40918a619c646169d96897f |
|
BLAKE2b-256 | 69ca4dade68c0646aa6b0113be2b6ac056ce84f4da5c2f2a7410936c9f37ad9a |
Hashes for websockets-6.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2f7d6567838369af074f0ef4d0b802d19fa1fee135d864acc656ceefa33136 |
|
MD5 | 68111670e2ce38cf658b5eabf14e7bfe |
|
BLAKE2b-256 | 6cf498e3e24666ab75f8726a3d20f195923191dd650d64c805662ceb8f675648 |
Hashes for websockets-6.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 669d1e46f165e0ad152ed8197f7edead22854a6c90419f544e0f234cc9dac6c4 |
|
MD5 | 918e4fd383b5f3104bf47340f4a227fc |
|
BLAKE2b-256 | 0c6ad048dfe820fc956e57bb1115f5eda5a1bef320172811f72c9924c8d6ebb5 |
Hashes for websockets-6.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e79a5a896bcee7fff24a788d72e5c69f13e61369d055f28113e71945a7eb1559 |
|
MD5 | 748d7a3d0b06846089df9e255110a363 |
|
BLAKE2b-256 | 89731f08b2ecbbb7e18e8c5e04ee0a062af11524aa2ea016b7e17123fd355a69 |
Hashes for websockets-6.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 695e34c4dbea18d09ab2c258994a8bf6a09564e762655408241f6a14592d2908 |
|
MD5 | 3045557e0f18c4f31b09762713e7c2fd |
|
BLAKE2b-256 | da0bc8fce17000873c1927ba4855ad9f5b558bfcded1dace638e8911ce83d6d0 |
Hashes for websockets-6.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee55eb6bcf23ecc975e6b47c127c201b913598f38b6a300075f84eeef2d3baff |
|
MD5 | d046c4584dcd52751137a81759d96c7b |
|
BLAKE2b-256 | 0ba9d5446e3c9657652b94ec0b10d6c5528a64860d9ac44db185b5bc896b6c2d |
Hashes for websockets-6.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fd2dd9a856f72e6ed06f82facfce01d119b88457cd4b47b7ae501e8e11eba9c |
|
MD5 | f4aba6881dc3f10ffc9fba2907a57c61 |
|
BLAKE2b-256 | 74304973b4694266c6c4f2840d0d58944afa3e5304b694ded10bb819da2e01f8 |
Hashes for websockets-6.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91ec98640220ae05b34b79ee88abf27f97ef7c61cf525eec57ea8fcea9f7dddb |
|
MD5 | 689218ed19733c1e2c930edd17a820ef |
|
BLAKE2b-256 | 5cfe99aeaf97985585baefca8d56125ec828ef5549276324ec319b63a4da686d |
Hashes for websockets-6.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82c0354ac39379d836719a77ee360ef865377aa6fdead87909d50248d0f05f4d |
|
MD5 | 7496c55ccadbb8fcd838c656e1b4af63 |
|
BLAKE2b-256 | e91b49ce066922f0b628c0c9cf51864525ccb505abb7886537f897c6550e7f0e |
Hashes for websockets-6.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 952be9540d83dba815569d5cb5f31708801e0bbfc3a8c5aef1890b57ed7e58bf |
|
MD5 | 32e9f7a545220120e8dc98b63b29cb76 |
|
BLAKE2b-256 | 0fd9e04264525261f352c6d9070f2f69fb83c5df6954aa5c1697b28732a12481 |
Hashes for websockets-6.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a16dac282b2fdae75178d0ed3d5b9bc3258dabfae50196cbb30578d84b6f6a6 |
|
MD5 | 1362a51f53ccfca0e2d8f44eb1be0a58 |
|
BLAKE2b-256 | 7dc557a9fcbd6d06f7287cd06983b2042f4240e9fd4c6564f8eef19ccb9efd81 |
Hashes for websockets-6.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79ca7cdda7ad4e3663ea3c43bfa8637fc5d5604c7737f19a8964781abbd1148d |
|
MD5 | 9b559b0af2039b321076def61b912aa9 |
|
BLAKE2b-256 | 02ae88f16d867890b883fec115544d0e9daf828faa0da458ad8a7f2bbc41a06d |
Hashes for websockets-6.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a1fa6072405648cb5b3688e9ed3b94be683ce4a4e5723e6f5d34859dee495c1 |
|
MD5 | b76637777365ed9c972d04f7927b8fa7 |
|
BLAKE2b-256 | 8ee88c959153f7e36258b410b90869c46a3f881a5a345539bf6b2a16049ea5f0 |
Hashes for websockets-6.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b2e03d69afa8d20253455e67b64de1a82ff8612db105113cccec35d3f8429f0 |
|
MD5 | 966df02ea385a2cb3dcbd52c5d47c903 |
|
BLAKE2b-256 | 8c307525ee9a9f7924e84577250be7e6a34eeecf127aa5bbe91dfed5750b13d3 |
Hashes for websockets-6.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c1f55a1274df9d6a37553fef8cff2958515438c58920897675c9bc70f5a0538 |
|
MD5 | 8812d6da24b58f86cd590529fade4946 |
|
BLAKE2b-256 | 2851d8193e729e315495cb22615fe84c5c646743a0ccf87fa1451e97b0df6a55 |
Hashes for websockets-6.0-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fa122e7adb24232247f8a89f2d9070bf64b7869daf93ac5e19546b409e47e96 |
|
MD5 | 5e74f49ade5bfa82ff427e4cdb8b2c84 |
|
BLAKE2b-256 | 2ab0d13f97bec6c26705df70ea72cfa098d124c00ce0903bed3336f222126b9f |
Hashes for websockets-6.0-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1414e6cbcea8d22843e7eafdfdfae3dd1aba41d1945f6ca66e4806c07c4f454 |
|
MD5 | a1f8b789a3da659097a7a05aeea9a174 |
|
BLAKE2b-256 | fde879b17f2a96376b2ba131af82794a85addb82f2010d43b354983bd2c29893 |
Hashes for websockets-6.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99ac266af38ba1b1fe13975aea01ac0e14bb5f3a3200d2c69f05385768b8568e |
|
MD5 | 794c15091a38285916cd74d1648e13a8 |
|
BLAKE2b-256 | 82d45c0faee603de297406cd493bcce47c27d91b0d151395ac459d2beb44f577 |
Hashes for websockets-6.0-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb998bd4d93af46b8b49ecf5a72c0a98e5cc6d57fdca6527ba78ad89d6606484 |
|
MD5 | 8a03ad44b83756b3b58d230e8467e6e2 |
|
BLAKE2b-256 | eaa37685ef9783607f216a14e0bc30d355e4c08b25e6c3b2dd1f3cb213c07b95 |
Hashes for websockets-6.0-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e02e57346f6a68523e3c43bbdf35dde5c440318d1f827208ae455f6a2ace446d |
|
MD5 | 072f5b87cac3ca743d118c83f32c4b0d |
|
BLAKE2b-256 | fe367ffb882b0dc18a5cead74b099b5a3d95d45b419b54b4d52e43c83b9c7b46 |