Skip to content

Latest commit

 

History

History
1663 lines (1060 loc) · 42.7 KB

changelog.rst

File metadata and controls

1663 lines (1060 loc) · 42.7 KB

Changelog

.. currentmodule:: websockets

Backwards-compatibility policy

websockets is intended for production use. Therefore, stability is a goal.

websockets also aims at providing the best API for WebSocket in Python.

While we value stability, we value progress more. When an improvement requires changing a public API, we make the change and document it in this changelog.

When possible with reasonable effort, we preserve backwards-compatibility for five years after the release that introduced the change.

When a release contains backwards-incompatible API changes, the major version is increased, else the minor version is increased. Patch versions are only for fixing regressions shortly after a release.

Only documented APIs are public. Undocumented, private APIs may change without notice.

15.1

In development

15.0.1

March 5, 2025

Bug fixes

  • Prevented an exception when exiting the interactive client.

15.0

February 16, 2025

Backwards-incompatible changes

Client connections use SOCKS and HTTP proxies automatically.

If a proxy is configured in the operating system or with an environment variable, websockets uses it automatically when connecting to a server. SOCKS proxies require installing the third-party library python-socks.

If you want to disable the proxy, add proxy=None when calling :func:`~asyncio.client.connect`.

See :doc:`proxies <../topics/proxies>` for details.

Keepalive is enabled in the :mod:`threading` implementation.

The :mod:`threading` implementation now sends Ping frames at regular intervals and closes the connection if it doesn't receive a matching Pong frame just like the :mod:`asyncio` implementation.

See :doc:`keepalive and latency <../topics/keepalive>` for details.

New features

Improvements

14.2

January 19, 2025

New features

Bug fixes

14.1

November 13, 2024

Improvements

  • Supported max_queue=None in the :mod:`asyncio` and :mod:`threading` implementations for consistency with the legacy implementation, even though this is never a good idea.
  • Added close_code and close_reason attributes in the :mod:`asyncio` and :mod:`threading` implementations for consistency with the legacy implementation.

Bug fixes

  • Once the connection is closed, messages previously received and buffered can be read in the :mod:`asyncio` and :mod:`threading` implementations, just like in the legacy implementation.

14.0

November 9, 2024

Backwards-incompatible changes

websockets 14.0 requires Python ≥ 3.9.

websockets 13.1 is the last version supporting Python 3.8.

The new :mod:`asyncio` implementation is now the default.

The following aliases in the websockets package were switched to the new :mod:`asyncio` implementation:

from websockets import connect, unix_connext
from websockets import broadcast, serve, unix_serve

If you're using any of them, then you must follow the :doc:`upgrade guide <../howto/upgrade>` immediately.

Alternatively, you may stick to the legacy :mod:`asyncio` implementation for now by importing it explicitly:

from websockets.legacy.client import connect, unix_connect
from websockets.legacy.server import broadcast, serve, unix_serve

The legacy :mod:`asyncio` implementation is now deprecated.

The :doc:`upgrade guide <../howto/upgrade>` provides complete instructions to migrate your application.

Aliases for deprecated API were removed from websockets.__all__, meaning that they cannot be imported with from websockets import * anymore.

Several API raise :exc:`ValueError` instead of :exc:`TypeError` on invalid arguments.

:func:`~asyncio.client.connect`, :func:`~asyncio.client.unix_connect`, and :func:`~asyncio.server.basic_auth` in the :mod:`asyncio` implementation as well as :func:`~sync.client.connect`, :func:`~sync.client.unix_connect`, :func:`~sync.server.serve`, :func:`~sync.server.unix_serve`, and :func:`~sync.server.basic_auth` in the :mod:`threading` implementation now raise :exc:`ValueError` when a required argument isn't provided or an argument that is incompatible with others is provided.

:attr:`Frame.data <frames.Frame.data>` is now a bytes-like object.

In addition to :class:`bytes`, it may be a :class:`bytearray` or a :class:`memoryview`. If you wrote an :class:`~extensions.Extension` that relies on methods not provided by these types, you must update your code.

The signature of :exc:`~exceptions.PayloadTooBig` changed.

If you wrote an extension that raises :exc:`~exceptions.PayloadTooBig` in :meth:`~extensions.Extension.decode`, for example, you must replace PayloadTooBig(f"over size limit ({size} > {max_size} bytes)") with PayloadTooBig(size, max_size).

New features

Improvements

Bug fixes

  • Clients no longer crash when the server rejects the opening handshake and the HTTP response doesn't Include a Content-Length header.
  • Returning an HTTP response in process_request or process_response doesn't generate a log message at the :data:`~logging.ERROR` level anymore.
  • Connections are closed with code 1007 (invalid data) when receiving invalid UTF-8 in a text frame.

13.1

September 21, 2024

Backwards-incompatible changes

The code and reason attributes of :exc:`~exceptions.ConnectionClosed` are deprecated.

They were removed from the documentation in version 10.0, due to their spec-compliant but counter-intuitive behavior, but they were kept in the code for backwards compatibility. They're now formally deprecated.

New features

Improvements

Bug fixes

13.0.1

August 28, 2024

Bug fixes

  • Restored the C extension in the source distribution.

13.0

August 20, 2024

Backwards-incompatible changes

Receiving the request path in the second parameter of connection handlers is deprecated.

If you implemented the connection handler of a server as:

async def handler(request, path):
  ...

You should switch to the pattern recommended since version 10.1:

async def handler(request):
    path = request.path  # only if handler() uses the path argument
    ...

The ssl_context argument of :func:`~sync.client.connect` and :func:`~sync.server.serve` in the :mod:`threading` implementation is renamed to ssl.

This aligns the API of the :mod:`threading` implementation with the :mod:`asyncio` implementation.

For backwards compatibility, ssl_context is still supported.

The WebSocketServer class in the :mod:`threading` implementation is renamed to :class:`~sync.server.Server`.

This change should be transparent because this class shouldn't be instantiated directly; :func:`~sync.server.serve` returns an instance.

Regardless, an alias provides backwards compatibility.

New features

websockets 11.0 introduces a new :mod:`asyncio` implementation.

This new implementation is intended to be a drop-in replacement for the current implementation. It will become the default in a future release.

Please try it and report any issue that you encounter! The :doc:`upgrade guide <../howto/upgrade>` explains everything you need to know about the upgrade process.

  • Validated compatibility with Python 3.12 and 3.13.

  • Added an option to receive text frames as :class:`bytes`, without decoding, in the :mod:`asyncio` implementation; also binary frames as :class:`str`.

  • Added :doc:`environment variables <../reference/variables>` to configure debug logs, the Server and User-Agent headers, as well as security limits.

    If you were monkey-patching constants, be aware that they were renamed, which will break your configuration. You must switch to the environment variables.

Improvements

  • The error message in server logs when a header is too long is more explicit.

Bug fixes

  • Fixed a bug in the :mod:`threading` implementation that could prevent the program from exiting when a connection wasn't closed properly.
  • Redirecting from a ws:// URI to a wss:// URI now works.
  • broadcast(raise_exceptions=True) no longer crashes when there isn't any exception.

12.0

October 21, 2023

Backwards-incompatible changes

websockets 12.0 requires Python ≥ 3.8.

websockets 11.0 is the last version supporting Python 3.7.

Improvements

11.0.3

May 7, 2023

Bug fixes

11.0.2

April 18, 2023

Bug fixes

  • Fixed a deadlock in the :mod:`threading` implementation when closing a connection without reading all messages.

11.0.1

April 6, 2023

Bug fixes

  • Restored the C extension in the source distribution.

11.0

April 2, 2023

Backwards-incompatible changes

The Sans-I/O implementation was moved.

Aliases provide compatibility for all previously public APIs according to the backwards-compatibility policy.

  • The connection module was renamed to protocol.
  • The connection.Connection, server.ServerConnection, and client.ClientConnection classes were renamed to protocol.Protocol, server.ServerProtocol, and client.ClientProtocol.

Sans-I/O protocol constructors now use keyword-only arguments.

If you instantiate :class:`~server.ServerProtocol` or :class:`~client.ClientProtocol` directly, make sure you are using keyword arguments.

Closing a connection without an empty close frame is OK.

Receiving an empty close frame now results in :exc:`~exceptions.ConnectionClosedOK` instead of :exc:`~exceptions.ConnectionClosedError`.

As a consequence, calling WebSocket.close() without arguments in a browser isn't reported as an error anymore.

:func:`~legacy.server.serve` times out on the opening handshake after 10 seconds by default.

You can adjust the timeout with the open_timeout parameter. Set it to :obj:`None` to disable the timeout entirely.

New features

websockets 11.0 introduces a :mod:`threading` implementation.

It may be more convenient if you don't need to manage many connections and you're more comfortable with :mod:`threading` than :mod:`asyncio`.

It is particularly suited to client applications that establish only one connection. It may be used for servers handling few connections.

See :func:`websockets.sync.client.connect` and :func:`websockets.sync.server.serve` for details.

Improvements

10.4

October 25, 2022

New features

Improvements

  • Improved FAQ.

10.3

April 17, 2022

Backwards-incompatible changes

The exception attribute of :class:`~http11.Request` and :class:`~http11.Response` is deprecated.

Use the handshake_exc attribute of :class:`~server.ServerProtocol` and :class:`~client.ClientProtocol` instead.

See :doc:`../howto/sansio` for details.

Improvements

10.2

February 21, 2022

Improvements

  • Made compression negotiation more lax for compatibility with Firefox.
  • Improved FAQ and quick start guide.

Bug fixes

10.1

November 14, 2021

New features

  • Added a tutorial.

  • Made the second parameter of connection handlers optional. The request path is available in the :attr:`~legacy.protocol.WebSocketCommonProtocol.path` attribute of the first argument.

    If you implemented the connection handler of a server as:

    async def handler(request, path):
        ...
    

    You should replace it with:

    async def handler(request):
        path = request.path  # only if handler() uses the path argument
        ...
    
  • Added python -m websockets --version.

Improvements

  • Added wheels for Python 3.10, PyPy 3.7, and for more platforms.
  • Reverted optimization of default compression settings for clients, mainly to avoid triggering bugs in poorly implemented servers like AWS API Gateway.
  • Mirrored the entire :class:`~asyncio.Server` API in :class:`~legacy.server.WebSocketServer`.
  • Improved performance for large messages on ARM processors.
  • Documented how to auto-reload on code changes in development.

Bug fixes

  • Avoided half-closing TCP connections that are already closed.

10.0

September 9, 2021

Backwards-incompatible changes

websockets 10.0 requires Python ≥ 3.7.

websockets 9.1 is the last version supporting Python 3.6.

The loop parameter is deprecated from all APIs.

This reflects a decision made in Python 3.8. See the release notes of Python 3.10 for details.

The loop parameter is also removed from :class:`~legacy.server.WebSocketServer`. This should be transparent.

:func:`~legacy.client.connect` times out after 10 seconds by default.

You can adjust the timeout with the open_timeout parameter. Set it to :obj:`None` to disable the timeout entirely.

The legacy_recv option is deprecated.

See the release notes of websockets 3.0 for details.

The signature of :exc:`~exceptions.ConnectionClosed` changed.

If you raise :exc:`~exceptions.ConnectionClosed` or a subclass, rather than catch them when websockets raises them, you must change your code.

A msg parameter was added to :exc:`~exceptions.InvalidURI`.

If you raise :exc:`~exceptions.InvalidURI`, rather than catch it when websockets raises it, you must change your code.

New features

websockets 10.0 introduces a Sans-I/O API for easier integration in third-party libraries.

If you're integrating websockets in a library, rather than just using it, look at the :doc:`Sans-I/O integration guide <../howto/sansio>`.

  • Added compatibility with Python 3.10.
  • Added :func:`~legacy.server.broadcast` to send a message to many clients.
  • Added support for reconnecting automatically by using :func:`~legacy.client.connect` as an asynchronous iterator.
  • Added open_timeout to :func:`~legacy.client.connect`.
  • Documented how to integrate with Django.
  • Documented how to deploy websockets in production, with several options.
  • Documented how to authenticate connections.
  • Documented how to broadcast messages to many connections.

Improvements

Bug fixes

  • Avoided a crash when receiving a ping while the connection is closing.

9.1

May 27, 2021

Security fix

websockets 9.1 fixes a security issue introduced in 8.0.

Version 8.0 was vulnerable to timing attacks on HTTP Basic Auth passwords (CVE-2021-33880).

9.0.2

May 15, 2021

Bug fixes

  • Restored compatibility of python -m websockets with Python < 3.9.
  • Restored compatibility with mypy.

9.0.1

May 2, 2021

Bug fixes

  • Fixed issues with the packaging of the 9.0 release.

9.0

May 1, 2021

Backwards-incompatible changes

Several modules are moved or deprecated.

Aliases provide compatibility for all previously public APIs according to the backwards-compatibility policy

  • :class:`~datastructures.Headers` and :exc:`~datastructures.MultipleValuesError` are moved from websockets.http to :mod:`websockets.datastructures`. If you're using them, you should adjust the import path.
  • The client, server, protocol, and auth modules were moved from the websockets package to a websockets.legacy sub-package. Despite the name, they're still fully supported.
  • The framing, handshake, headers, http, and uri modules in the websockets package are deprecated. These modules provided low-level APIs for reuse by other projects, but they didn't reach that goal. Keeping these APIs public makes it more difficult to improve websockets.

These changes pave the path for a refactoring that should be a transparent upgrade for most uses and facilitate integration by other projects.

Convenience imports from websockets are performed lazily.

While Python supports this, tools relying on static code analysis don't. This breaks auto-completion in an IDE or type checking with mypy.

If you depend on such tools, use the real import paths, which can be found in the API documentation, for example:

from websockets.client import connect
from websockets.server import serve

New features

  • Added compatibility with Python 3.9.

Improvements

Bug fixes

  • Fixed sending fragmented, compressed messages.
  • Fixed Host header sent when connecting to an IPv6 address.
  • Fixed creating a client or a server with an existing Unix socket.
  • Aligned maximum cookie size with popular web browsers.
  • Ensured cancellation always propagates, even on Python versions where :exc:`~asyncio.CancelledError` inherits from :exc:`Exception`.

8.1

November 1, 2019

New features

  • Added compatibility with Python 3.8.

8.0.2

July 31, 2019

Bug fixes

  • Restored the ability to pass a socket with the sock parameter of :func:`~legacy.server.serve`.
  • Removed an incorrect assertion when a connection drops.

8.0.1

July 21, 2019

Bug fixes

  • Restored the ability to import WebSocketProtocolError from websockets.

8.0

July 7, 2019

Backwards-incompatible changes

websockets 8.0 requires Python ≥ 3.6.

websockets 7.0 is the last version supporting Python 3.4 and 3.5.

process_request is now expected to be a coroutine.

If you're passing a process_request argument to :func:`~legacy.server.serve` or :class:`~legacy.server.WebSocketServerProtocol`, or if you're overriding :meth:`~legacy.server.WebSocketServerProtocol.process_request` in a subclass, define it with async def instead of def. Previously, both were supported.

For backwards compatibility, functions are still accepted, but mixing functions and coroutines won't work in some inheritance scenarios.

max_queue must be :obj:`None` to disable the limit.

If you were setting max_queue=0 to make the queue of incoming messages unbounded, change it to max_queue=None.

The host, port, and secure attributes of :class:`~legacy.protocol.WebSocketCommonProtocol` are deprecated.

Use :attr:`~legacy.protocol.WebSocketCommonProtocol.local_address` in servers and :attr:`~legacy.protocol.WebSocketCommonProtocol.remote_address` in clients instead of host and port.

WebSocketProtocolError is renamed to :exc:`~exceptions.ProtocolError`.

An alias provides backwards compatibility.

read_response() now returns the reason phrase.

If you're using this low-level API, you must change your code.

New features

Improvements

Bug fixes

  • Prevented spurious log messages about :exc:`~exceptions.ConnectionClosed` exceptions in keepalive ping task. If you were using ping_timeout=None as a workaround, you can remove it.
  • Avoided a crash when a extra_headers callable returns :obj:`None`.

7.0

November 1, 2018

Backwards-incompatible changes

Keepalive is enabled by default.

websockets now sends Ping frames at regular intervals and closes the connection if it doesn't receive a matching Pong frame. See :class:`~legacy.protocol.WebSocketCommonProtocol` for details.

Termination of connections by :meth:`WebSocketServer.close() <legacy.server.WebSocketServer.close>` changes.

Previously, connections handlers were canceled. Now, connections are closed with close code 1001 (going away).

From the perspective of the connection handler, this is the same as if the remote endpoint was disconnecting. This removes the need to prepare for :exc:`~asyncio.CancelledError` in connection handlers.

You can restore the previous behavior by adding the following line at the beginning of connection handlers:

def handler(websocket, path):
    closed = asyncio.ensure_future(websocket.wait_closed())
    closed.add_done_callback(lambda task: task.cancel())

Calling :meth:`~legacy.protocol.WebSocketCommonProtocol.recv` concurrently raises a :exc:`RuntimeError`.

Concurrent calls lead to non-deterministic behavior because there are no guarantees about which coroutine will receive which message.

The timeout argument of :func:`~legacy.server.serve` and :func:`~legacy.client.connect` is renamed to close_timeout .

This prevents confusion with ping_timeout.

For backwards compatibility, timeout is still supported.

The origins argument of :func:`~legacy.server.serve` changes.

Include :obj:`None` in the list rather than '' to allow requests that don't contain an Origin header.

Pending pings aren't canceled when the connection is closed.

A ping — as in ping = await websocket.ping() — for which no pong was received yet used to be canceled when the connection is closed, so that await ping raised :exc:`~asyncio.CancelledError`.

Now await ping raises :exc:`~exceptions.ConnectionClosed` like other public APIs.

New features

Improvements

  • Improved handling of multiple HTTP headers with the same name.
  • Improved error messages when a required HTTP header is missing.

Bug fixes

6.0

July 16, 2018

Backwards-incompatible changes

The :class:`~datastructures.Headers` class is introduced and several APIs are updated to use it.

Since :class:`~datastructures.Headers` and http.client.HTTPMessage provide similar APIs, much of the code dealing with HTTP headers won't require changes.

New features

  • Added compatibility with Python 3.7.

5.0.1

May 24, 2018

Bug fixes

5.0

May 22, 2018

Security fix

websockets 5.0 fixes a security issue introduced in 4.0.

Version 4.0 was vulnerable to denial of service by memory exhaustion because it didn't enforce max_size when decompressing compressed messages (CVE-2018-1000518).

Backwards-incompatible changes

A user_info field is added to the return value of parse_uri and WebSocketURI.

If you're unpacking WebSocketURI into four variables, adjust your code to account for that fifth field.

New features

Improvements

  • Iterating on incoming messages no longer raises an exception when the connection terminates with close code 1001 (going away).
  • A plain HTTP request now receives a 426 Upgrade Required response and doesn't log a stack trace.
  • If a :meth:`~legacy.protocol.WebSocketCommonProtocol.ping` doesn't receive a pong, it's canceled when the connection is closed.
  • Reported the cause of :exc:`~exceptions.ConnectionClosed` exceptions.
  • Stopped logging stack traces when the TCP connection dies prematurely.
  • Prevented writing to a closing TCP connection during unclean shutdowns.
  • Made connection termination more robust to network congestion.
  • Prevented processing of incoming frames after failing the connection.
  • Updated documentation with new features from Python 3.6.
  • Improved several sections of the documentation.

Bug fixes

4.0.1

November 2, 2017

Bug fixes

  • Fixed issues with the packaging of the 4.0 release.

4.0

November 2, 2017

Backwards-incompatible changes

websockets 4.0 requires Python ≥ 3.4.

websockets 3.4 is the last version supporting Python 3.3.

Compression is enabled by default.

In August 2017, Firefox and Chrome support the permessage-deflate extension, but not Safari and IE.

Compression should improve performance but it increases RAM and CPU use.

If you want to disable compression, add compression=None when calling :func:`~legacy.server.serve` or :func:`~legacy.client.connect`.

The state_name attribute of protocols is deprecated.

Use protocol.state.name instead of protocol.state_name.

New features

Improvements

  • Reorganized and extended documentation.
  • Rewrote connection termination to increase robustness in edge cases.
  • Reduced verbosity of "Failing the WebSocket connection" logs.

Bug fixes

  • Aborted connections if they don't close within the configured timeout.
  • Stopped leaking pending tasks when :meth:`~asyncio.Task.cancel` is called on a connection while it's being closed.

3.4

August 20, 2017

Backwards-incompatible changes

InvalidStatus is replaced by :class:`~exceptions.InvalidStatusCode`.

This exception is raised when :func:`~legacy.client.connect` receives an invalid response status code from the server.

New features

Improvements

  • Renamed :func:`~legacy.server.serve` and :func:`~legacy.client.connect`'s klass argument to create_protocol to reflect that it can also be a callable. For backwards compatibility, klass is still supported.
  • Rewrote HTTP handling for simplicity and performance.
  • Added an optional C extension to speed up low-level operations.

Bug fixes

3.3

March 29, 2017

New features

  • Ensured compatibility with Python 3.6.

Improvements

  • Reduced noise in logs caused by connection resets.

Bug fixes

  • Avoided crashing on concurrent writes on slow connections.

3.2

August 17, 2016

New features

Improvements

  • Made server shutdown more robust.

3.1

April 21, 2016

New features

  • Added flow control for incoming data.

Bug fixes

  • Avoided a warning when closing a connection before the opening handshake.

3.0

December 25, 2015

Backwards-incompatible changes

:meth:`~legacy.protocol.WebSocketCommonProtocol.recv` now raises an exception when the connection is closed.

:meth:`~legacy.protocol.WebSocketCommonProtocol.recv` used to return :obj:`None` when the connection was closed. This required checking the return value of every call:

message = await websocket.recv()
if message is None:
    return

Now it raises a :exc:`~exceptions.ConnectionClosed` exception instead. This is more Pythonic. The previous code can be simplified to:

message = await websocket.recv()

When implementing a server, there's no strong reason to handle such exceptions. Let them bubble up, terminate the handler coroutine, and the server will simply ignore them.

In order to avoid stranding projects built upon an earlier version, the previous behavior can be restored by passing legacy_recv=True to :func:`~legacy.server.serve`, :func:`~legacy.client.connect`, :class:`~legacy.server.WebSocketServerProtocol`, or :class:`~legacy.client.WebSocketClientProtocol`.

New features

Improvements

  • Updated documentation with await and async syntax from Python 3.5.
  • Worked around an :mod:`asyncio` bug affecting connection termination under load.
  • Improved documentation.

2.7

November 18, 2015

New features

  • Added compatibility with Python 3.5.

Improvements

  • Refreshed documentation.

2.6

August 18, 2015

New features

  • Added local_address and remote_address attributes on protocols.
  • Closed open connections with code 1001 when a server shuts down.

Bug fixes

  • Avoided TCP fragmentation of small frames.

2.5

July 28, 2015

New features

  • Provided access to handshake request and response HTTP headers.
  • Allowed customizing handshake request and response HTTP headers.
  • Added support for running on a non-default event loop.

Improvements

  • Improved documentation.
  • Sent a 403 status code instead of 400 when request Origin isn't allowed.
  • Clarified that the closing handshake can be initiated by the client.
  • Set the close code and reason more consistently.
  • Strengthened connection termination.

Bug fixes

2.4

January 31, 2015

New features

2.3

November 3, 2014

Improvements

  • Improved compliance of close codes.

2.2

July 28, 2014

New features

  • Added support for limiting message size.

2.1

April 26, 2014

New features

  • Added host, port and secure attributes on protocols.
  • Added support for providing and checking Origin.

2.0

February 16, 2014

Backwards-incompatible changes

:meth:`~legacy.protocol.WebSocketCommonProtocol.send`, :meth:`~legacy.protocol.WebSocketCommonProtocol.ping`, and :meth:`~legacy.protocol.WebSocketCommonProtocol.pong` are now coroutines.

They used to be functions.

Instead of:

websocket.send(message)

you must write:

await websocket.send(message)

New features

  • Added flow control for outgoing data.

1.0

November 14, 2013

New features

  • Initial public release.