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-7.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e13239952694b8b831088431d15f771beace10edfcf9ef230cefea14f18508f |
|
MD5 | 452140e1f7ac2866660e27a5aabd3832 |
|
BLAKE2b-256 | 8a7d7f3a5af575187443e2b6d12611778f73413df2286a71af1a8b012ece1f92 |
Hashes for websockets-7.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04b42a1b57096ffa5627d6a78ea1ff7fad3bc2c0331ffc17bc32a4024da7fea0 |
|
MD5 | da53a7ecdaa42bee7467e9fada6834cc |
|
BLAKE2b-256 | 97391edce95cb8cb651df1bf8c000181c21f22f34554dffafe1530137bc88733 |
Hashes for websockets-7.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 232fac8a1978fc1dead4b1c2fa27c7756750fb393eb4ac52f6bc87ba7242b2fa |
|
MD5 | 02635a87b9cb7080a786c9b58514433e |
|
BLAKE2b-256 | aa531dbfbe51e8ba9a2b9bc0b7201df77fe597f1e57b6b5d9bb094d3729aeecf |
Hashes for websockets-7.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8d59627702d2ff27cb495ca1abdea8bd8d581de425c56e93bff6517134e0a9b |
|
MD5 | fc75bf01d76d68a3c419d9bc12baf3c0 |
|
BLAKE2b-256 | 62ae7653635be27bc60a4a586563f7af5d20ae893cf2ba0dcc8fc8f605cd0f3f |
Hashes for websockets-7.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc30cdf2e949a2225b012a7911d1d031df3d23e99b7eda7dfc982dc4a860dae9 |
|
MD5 | 2ce94bfb43f787a5136b096c9a7b0c9c |
|
BLAKE2b-256 | 47d01f156ca4477e60a1e98de1b4afabd610d24cdaeafe196e5a204aa41863fa |
Hashes for websockets-7.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fcc8681e9981b9b511cdee7c580d5b005f3bb86b65bde2188e04a29f1d63317 |
|
MD5 | cefafc85f01d010fad14f9cb89e5ebba |
|
BLAKE2b-256 | 61e45898fd4382264c4a49efc70b44f9a336f400a28df003298ea4f999090dad |
Hashes for websockets-7.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d13bf5197a92149dc0badcc2b699267ff65a867029f465accfca8abab95f412 |
|
MD5 | 73acdf8bf75e2b16413a110a88f7b8ec |
|
BLAKE2b-256 | 356b981cbdeb68f35588b9077a6279d938c3792aebeb844608199bdff7e35846 |
Hashes for websockets-7.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79691794288bc51e2a3b8de2bc0272ca8355d0b8503077ea57c0716e840ebaef |
|
MD5 | 84752811a400eb59701afb0c4a340a9c |
|
BLAKE2b-256 | 43718bfa882b9c502c36e5c9ef6732969533670d2b039cbf95a82ced8f762b80 |
Hashes for websockets-7.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51642ea3a00772d1e48fb0c492f0d3ae3b6474f34d20eca005a83f8c9c06c561 |
|
MD5 | 1580b8835937f8da5944b7d69c8ea4db |
|
BLAKE2b-256 | cb509b8c958d19a47f117944228ea8c007eee58b5c0f0aaa856343d0a7c1c0b2 |
Hashes for websockets-7.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bf4c8097440eff22bc78ec76fe2a865a6e658b6977a504679aaf08f02c121da |
|
MD5 | 87714a13fea1eee4e7fdffefa4d729fd |
|
BLAKE2b-256 | e8ef8c675bdae68b9c756fe6f9238ae7eac8653aaba793370e988f49ee4e5fd2 |
Hashes for websockets-7.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d40f081187f7b54d7a99d8a5c782eaa4edc335a057aa54c85059272ed826dc09 |
|
MD5 | b2bd2b487e0778841cbb6eabba2beaaf |
|
BLAKE2b-256 | bc37417e9de37f17f48ed25080ecba45fe902d8daf4ed49ca3b1d00e509bcbd2 |
Hashes for websockets-7.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 564d2675682bd497b59907d2205031acbf7d3fadf8c763b689b9ede20300b215 |
|
MD5 | b6f87e0c6150e67a29d233daca596484 |
|
BLAKE2b-256 | a43ee46039a8ae59ba6a01b8f25d16f80098bb3e457a463ccbfd57edd7303913 |
Hashes for websockets-7.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10d89d4326045bf5e15e83e9867c85d686b612822e4d8f149cf4840aab5f46e0 |
|
MD5 | 9f00f3f31f5256750691f8778d5c1139 |
|
BLAKE2b-256 | f5e2569b96cf3cd4e7e4aad036282c6fc61124de70ca976fb0cf86c2a89633a3 |
Hashes for websockets-7.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1df1a58ed2468c7b7ce9a2f9752a32ad08eac2bcd56318625c3647c2cd2da6f |
|
MD5 | b0c39a122e4e5a100bb88283173aa3ea |
|
BLAKE2b-256 | c96cf2a52ca175933e2937bbc8c1830209d11bc0d3023488b91171e629d19959 |
Hashes for websockets-7.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55d86102282a636e195dad68aaaf85b81d0bef449d7e2ef2ff79ac450bb25d53 |
|
MD5 | 3d3c5b4b5122727f89a1c3fada0cf519 |
|
BLAKE2b-256 | 4b68691bc80df331a14c41baef569df7d9e2b91f77fc931ead4fb8c67f707f74 |
Hashes for websockets-7.0-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90ea6b3e7787620bb295a4ae050d2811c807d65b1486749414f78cfd6fb61489 |
|
MD5 | e70c25daedf1f54141e567d7354a6366 |
|
BLAKE2b-256 | 184ab2bbb27930485e92bb6b952aab2f5faaae86627a0eca5ef98918a44a7ec7 |
Hashes for websockets-7.0-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e98d0cec437097f09c7834a11c69d79fe6241729b23f656cfc227e93294fc242 |
|
MD5 | 62e129d65fbce8dd4ca926a8dc68a37f |
|
BLAKE2b-256 | d64665faf943524682d02a9bc0958d34d3594dcb5f3d2c9279360bdc42a93bcb |
Hashes for websockets-7.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5edb2524d4032be4564c65dc4f9d01e79fe8fad5f966e5b552f4e5164fef0885 |
|
MD5 | 810d43eacb27c6a42bbb0686add82e96 |
|
BLAKE2b-256 | 217e72e1149030517bcee471e6faab5662b262e98c07c12949dbcfee2625a1b5 |
Hashes for websockets-7.0-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eda665f6789edb9b57b57a159b9c55482cbe5b046d7db458948370554b16439 |
|
MD5 | fc6734e6de43468043e3ad8d043e9c73 |
|
BLAKE2b-256 | 348911ea44fb848a28ad0984467968d53b575e66fc3af1dc149ea6759c2b4949 |
Hashes for websockets-7.0-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e447e05ec88b1b408a4c9cde85aa6f4b04f06aa874b9f0b8e8319faf51b1fee |
|
MD5 | ed88d77b3b820c6035319faddd8719e6 |
|
BLAKE2b-256 | 95905e1c7b48c922becd1a98ba79ce98a96a12b4edb48d6237a6ce3da55cc81c |