Skip to main content

An implementation of the WebSocket Protocol (RFC 6455 & 7692)

Project description

websockets

rtd pypi-v pypi-pyversions pypi-l pypi-wheel circleci codecov

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?

Get started with the tutorial!

Why should I use websockets?

The development of websockets is shaped by four principles:

  1. 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.

  2. 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.

  3. Quality: websockets is heavily tested. Continuous integration fails under 100% branch coverage. Also it passes the industry-standard Autobahn Testsuite.

  4. 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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

websockets-8.0.tar.gz (57.3 kB view details)

Uploaded Source

Built Distributions

websockets-8.0-cp37-cp37m-win_amd64.whl (65.7 kB view details)

Uploaded CPython 3.7m Windows x86-64

websockets-8.0-cp37-cp37m-win32.whl (65.1 kB view details)

Uploaded CPython 3.7m Windows x86

websockets-8.0-cp37-cp37m-manylinux1_x86_64.whl (72.6 kB view details)

Uploaded CPython 3.7m

websockets-8.0-cp37-cp37m-manylinux1_i686.whl (71.9 kB view details)

Uploaded CPython 3.7m

websockets-8.0-cp37-cp37m-macosx_10_6_intel.whl (65.8 kB view details)

Uploaded CPython 3.7m macOS 10.6+ intel

websockets-8.0-cp36-cp36m-win_amd64.whl (65.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

websockets-8.0-cp36-cp36m-win32.whl (65.1 kB view details)

Uploaded CPython 3.6m Windows x86

websockets-8.0-cp36-cp36m-manylinux1_x86_64.whl (72.6 kB view details)

Uploaded CPython 3.6m

websockets-8.0-cp36-cp36m-manylinux1_i686.whl (71.9 kB view details)

Uploaded CPython 3.6m

websockets-8.0-cp36-cp36m-macosx_10_6_intel.whl (65.8 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

File details

Details for the file websockets-8.0.tar.gz.

File metadata

  • Download URL: websockets-8.0.tar.gz
  • Upload date:
  • Size: 57.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for websockets-8.0.tar.gz
Algorithm Hash digest
SHA256 945d98696c94bfa5b6d9d3aa98f2344f402bffe6c07c1920632419a41363f509
MD5 18af38883bbbb618272b67e365131466
BLAKE2b-256 a2b55afa7f779fcbb596cb42d4f1ea1ea6b8cf316bda227d4a5280400a2817fb

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: websockets-8.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 65.7 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for websockets-8.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 4a03f31084b2b6a58a5750de91ec5f25c82b5c4ac812d70ca0347af819b10d1c
MD5 6fd61ea55b3f08a03c6b68c6d2263d73
BLAKE2b-256 bc3bd475aa1144dc8efc8c2caded6da5dc82ea9d4dc7c460d2dfe62ae4e98454

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp37-cp37m-win32.whl.

File metadata

  • Download URL: websockets-8.0-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 65.1 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for websockets-8.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 e54f809a0d8b1155bd2efef669d81cb0d577184a827001cc56d6e223b40cd706
MD5 bc699d5df063d664fbaeb7d97c8b8a35
BLAKE2b-256 447e57854de1a1ba06ff2c2e0f98063a802bc96837e1f9c088debad90bf933b7

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: websockets-8.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 72.6 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for websockets-8.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a120055616208a82609f61fe3a5008db173cad54f7c4fec5f3298fd1e271f0de
MD5 593848a7d23acae66f990f18a1ca5337
BLAKE2b-256 f020f308288b9c31903f53b214cbe1c9d34a0e4097b80a54f7e64aaa3af170b2

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp37-cp37m-manylinux1_i686.whl.

File metadata

  • Download URL: websockets-8.0-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 71.9 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for websockets-8.0-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 58efc149c131897e834168e4ec8a0ae0fe7a189526d0d3fc604d8691053bd564
MD5 11a6c48525d242c86e516c90be0ca606
BLAKE2b-256 4f0ee419dd41bf2e9f774a6783456ffeddfa3506a4e995b97587207764a8a581

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp37-cp37m-macosx_10_6_intel.whl.

File metadata

  • Download URL: websockets-8.0-cp37-cp37m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 65.8 kB
  • Tags: CPython 3.7m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for websockets-8.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 a220f1acbe656b873860a30fafa98ac99ad6a9d5106ab5c13e7e68bd4dbc4af8
MD5 4375848ad809e4926fa30a7fcf4b7e1f
BLAKE2b-256 54f91691898e93b2d6702b5162c8ef0985d12a97f347e6477d1e27a7233be76f

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: websockets-8.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 65.7 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for websockets-8.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 0399adba0c5200260f1935231324678ce8b203b1e407214ed5c38a3e464a1eca
MD5 2e2726bd467385480ceb2d8a9f0fb60d
BLAKE2b-256 f9e40a82c9d2d688864ed32853b3e6cef271de35911c429b37d0c5db74ea0944

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp36-cp36m-win32.whl.

File metadata

  • Download URL: websockets-8.0-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 65.1 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for websockets-8.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 0fafa13554f8e1d2a3231e7d958f7fd42661c6ada16d0e5de7be52b2ff5f70bb
MD5 138367fadff91917daa26181bfff6618
BLAKE2b-256 091ab297a767e283caba34b2295b68ea38fa92bf5c86c73a841dd1cdb00c7b07

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: websockets-8.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 72.6 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for websockets-8.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7bf282162e2f9a33003a7b798ef4ae728aab63792b14343bb5a7943a412d7235
MD5 c472365c88ce26e054d6f6880adfab5b
BLAKE2b-256 615e2fe6afbb796c6ac5c006460b5503cd674d33706660337f2dbff10d4aa12d

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp36-cp36m-manylinux1_i686.whl.

File metadata

  • Download URL: websockets-8.0-cp36-cp36m-manylinux1_i686.whl
  • Upload date:
  • Size: 71.9 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for websockets-8.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 dcff46946ed9c3191be22cb839280a5be1b72df6aaf731a1a90db2cc9c2f32db
MD5 ea38fc13e87ec521c03a8422536bbfa7
BLAKE2b-256 23a2b66f69268e116236c7ac47ad733d906cc52b4143a0a1526aea84e2f1e6ca

See more details on using hashes here.

File details

Details for the file websockets-8.0-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

  • Download URL: websockets-8.0-cp36-cp36m-macosx_10_6_intel.whl
  • Upload date:
  • Size: 65.8 kB
  • Tags: CPython 3.6m, macOS 10.6+ intel
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for websockets-8.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 787755b149320a3d7b47556946f7226a125f4aa47b2d29eeae5471205018b088
MD5 0be0cc799814f15a6c3c4435d17399cd
BLAKE2b-256 0263309f3b3954e6cef79c5c200fe574a89708d141c99168fe3eb88ac53d4b5b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page