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:
#!/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 corountine-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 Distributions
Built Distributions
Hashes for websockets-4.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 093623790afe43998fc997509ed05dc28fe0604d49f32a5a4de682767d62af30 |
|
MD5 | b0b1637e3f75f71051ff90835ab1701a |
|
BLAKE2b-256 | 2d30adb6de8b21541214606c4506902dee6313217ce8b61ba572a0555418d5c8 |
Hashes for websockets-4.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98216a9c7b5f95a8b0b9680db3696cc34798c76d70153e35a3efc7d1ce7992a9 |
|
MD5 | 4b702e7d7aeee87eb9256300cc485a73 |
|
BLAKE2b-256 | 5f000cbe5814e9a2d5cbd420f8f131ff7306e6ba9ee95a9a3540f27bff69841a |
Hashes for websockets-4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 557ec0d3a67667fbc8367694fe9c68cb8f4a0ed5a28d3a2bb38079e06d582c0b |
|
MD5 | 405f8da9e8f4aebbc2d31a088182790b |
|
BLAKE2b-256 | 8ec0299825af6f915f6996a9e4351fda10bf9292f57ceb08ae005e66a91d982a |
Hashes for websockets-4.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 720ed7de9eb4de2287872aba00ead7e11438855436be3c4eba7d9e5021a52e1d |
|
MD5 | 888ade94263d5ead31d754654fd4331c |
|
BLAKE2b-256 | 6897d6f11dded820f1c2aa9e97dfa4718e5f8d3d2b7821bbd9366f4e290100a1 |
Hashes for websockets-4.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba4e5692ac160e4568425dfedfc5917861bd822864ae473b77bbd46942a28245 |
|
MD5 | 2d982da22debc9c3c8300414ec040572 |
|
BLAKE2b-256 | 279bc577e4714db79e09ead7c0c5846e7e82065dd2539f5d8c8d15cf293a5f1c |
Hashes for websockets-4.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e634aa9e663eeb8b814c9dc42adc9f96f0effaa4e2310ccfee08b7fd7a149389 |
|
MD5 | 7d98425f625bca7492af016d507cdcc5 |
|
BLAKE2b-256 | f44d016b5ea48256ac26d3c3b403683ec8155fac42acdf3ad45483e53635ce25 |
Hashes for websockets-4.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05c08772a66d4e509418cd4f8f0efd0f9732e698521d8c7492ba43aee8c6b85f |
|
MD5 | bafe475b25f383c52a1ba4b00cee2562 |
|
BLAKE2b-256 | e7c9efbac71ad380d93298acafe40d8e4db0987c9dc7eb06a4fb69ec0baab704 |
Hashes for websockets-4.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d11212c412ce22f6ff842753e950d0e265e123f2529a85f1ff4e8cd1f36bcba6 |
|
MD5 | 7e6319224224f8bd3e9ed7653a341d61 |
|
BLAKE2b-256 | bbc5c14b61da3b93f2d7d6c34d1ed58d0457c66f49d0ff16f47dac1dbd4d7171 |
Hashes for websockets-4.0-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 177ffe213a02980b4351ef1c3c3fe207d92b794921d6b472f27fee5843d9e391 |
|
MD5 | 8285f26a6e2611f46e65b3d189f82913 |
|
BLAKE2b-256 | 14248ecd8bf8f8f43f6b3df808d5880a3ab533815a949ce962ff992921abcf5f |
Hashes for websockets-4.0-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efc06608064fe6060dc2744acdc6046e5ca2902caf487cdd8b80141739a8626c |
|
MD5 | 49da75853ad4cb4537b0c8a0cbe76733 |
|
BLAKE2b-256 | 66a6d528c8fa7f4ce2b445de0268dafc5a0aecd1697d30737202ad008c8b6b3a |
Hashes for websockets-4.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a81c4149a076b8a406020f5f5c82966321a540b9bab1a4e4580bed85b0da10cd |
|
MD5 | cd05f7958d515e911e2b59164aa02f95 |
|
BLAKE2b-256 | ba93b504b21aba4a901a7cba119b20aac46807b72826604ea3ccb680f607d1f3 |
Hashes for websockets-4.0-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf5aa50e48d777f231fcbe3c43e86dd8a1198ee0d47d8c472359bfb07893f0d9 |
|
MD5 | e41f4951cf2423a1828b1619944b53ee |
|
BLAKE2b-256 | 19b87a518223c0c0d1f1afebe41fd14efb56610a5faa1042bf9daa117548c1be |