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 Distribution
Built Distributions
Hashes for websockets-4.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f3e5a52cab6daa3d432c7b0de0a14109be39d2bfaad033ee5de4a3d3e11dcdf |
|
MD5 | 4e2d63be752e357f9373fd907e045f26 |
|
BLAKE2b-256 | 16f60ca33b5cdb231926d27ea5f8796518bcaebeeba359094f33584c2e9c7781 |
Hashes for websockets-4.0.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64896a6b3368c959b8096b655e46f03dfa65b96745249f374bd6a35705cc3489 |
|
MD5 | 50e5065679c3fbf8a0fcf8333c61de81 |
|
BLAKE2b-256 | 264d5efee3e39bf47dbe1d84c157b7d618b569d9068d79e385e52f8dde688ac8 |
Hashes for websockets-4.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 341824d8c9ad53fc43cca3fa9407f294125fa258592f7676640396501448e57e |
|
MD5 | 780d324ddddfef89c75825c3d868e771 |
|
BLAKE2b-256 | 87bd532f1456c439accef8ddf54e3bf20081c416a4ce615ba7097218d669ff53 |
Hashes for websockets-4.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df87698022aef2596bffdfecc96d656db59c8d719708c8a471daa815ee61656 |
|
MD5 | acfbe1dae7ba4c321aec39949b2d2505 |
|
BLAKE2b-256 | 20ef311a66a4b295778aa9acd7eb784232fe58ae9b80d007b2d890bfe17f6f6f |
Hashes for websockets-4.0.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 367ff945bc0950ad9634591e2afe50bf2222bc4fad1088a386c4bb700888026e |
|
MD5 | 96aab51960a54f70b158dbf8acb533a3 |
|
BLAKE2b-256 | 4b9576a39368d0615c9eb8d26288833438bf8887a73cf9767cc2e6c6d27efeb3 |
Hashes for websockets-4.0.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fecf51c13195c416c22422353b306dddb9c752e4b80b21e0fa1fccbe38246677 |
|
MD5 | d9ae5bf8ed98701ea5b755d7ff0dc133 |
|
BLAKE2b-256 | 48a3762809b60a9154e03cfa033a6142c4bb377e81597f2bff9fa173b583a975 |
Hashes for websockets-4.0.1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80188abdadd23edaaea05ce761dc9a2e1df31a74a0533967f0dcd9560c85add0 |
|
MD5 | d01c8d9748a0ecb723c7bb4aadba4961 |
|
BLAKE2b-256 | b47290f7c5e25dfd72e262ca9a93c99ab136d904fd85b4ba531d6718b9bc3837 |
Hashes for websockets-4.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1a0572b6edb22c9208e3e5381064e09d287d2a915f90233fef994ee7a14a935 |
|
MD5 | 304c0ce02dfb99840a4bb71e9d890bf6 |
|
BLAKE2b-256 | 4a30f68f8e72901609397ced5cd5b59002716b3e64b1a364631124820a06fe0a |
Hashes for websockets-4.0.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3859ca16c229ddb0fa21c5090e4efcb037c08ce69b0c1dfed6122c3f98cd0c22 |
|
MD5 | ab057eb6668319da68177ae4c5442705 |
|
BLAKE2b-256 | 89fd59a2d98ddd60b0b8b70188000d23fc65a4fdb8a1e131e9d9f47af033a4a7 |
Hashes for websockets-4.0.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebdd4f18fe7e3bea9bd3bf446b0f4117739478caa2c76e4f0fb72cc45b03cbd7 |
|
MD5 | ae216292441574dc7f5801293ea78dec |
|
BLAKE2b-256 | 161c8c3480b64cef5b2d172ab4c425b944501dee0c8c2ab2769e44c2e8225c60 |
Hashes for websockets-4.0.1-cp34-cp34m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d425ae081fb4ba1eef9ecf30472ffd79f8e868297ccc7a47993c96dbf2a819c |
|
MD5 | 8599e064139c51b48dff0df9cbc009a2 |
|
BLAKE2b-256 | f562f11a112ca9a165df2c55cc72d8a87d4ef25cdd658757d0a9787568982384 |
Hashes for websockets-4.0.1-cp34-cp34m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd81af8cf3e69f9a97f3a6c0623a0527de0f922c2df725f00cd7646d478af632 |
|
MD5 | 11578fec24f8869ed86b0b8f10bf3585 |
|
BLAKE2b-256 | 03fff7c7462fc4684f36b4a4938547d6fe9279e48861eeaaba91de836762e760 |
Hashes for websockets-4.0.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da7610a017f5343fdf765f4e0eb6fd0dfd08264ca1565212b110836d9367fc9c |
|
MD5 | 08c4bcf8f2690171951687b815b1fdc6 |
|
BLAKE2b-256 | 4b0f3ae232aea7c32a8760a29e8f72c7b0796d920c740bbead07f893e359a872 |
Hashes for websockets-4.0.1-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c31bc832d529dc7583d324eb6c836a4f362032a1902723c112cf57883488d8c |
|
MD5 | 33f4f7e91d035673214023e3e13e317c |
|
BLAKE2b-256 | 845b3f23eb26208d177e7bca575bb9cfb3ce68285fc24efe5d5ac2609f325caa |
Hashes for websockets-4.0.1-cp34-cp34m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5192da704535a7cbf76d6e99c1ec4af7e8d1288252bf5a2385d414509ded0cf |
|
MD5 | 5d3a20307fc6bbd9b4538a1a5f86d332 |
|
BLAKE2b-256 | 1e45a2fa5e33d395ff33b1e8b3744a0f19a57e69b0a71093ab1074ece0ea21db |