Skip to content

DeprecationWarning with websockets>=14: runtime import of WebSocketClientProtocol#1666

Description

@23f3001135

Hi 馃憢

With python-binance==1.0.34 and websockets>=14, importing the websocket client triggers deprecation warnings:

--- Start ---
.venv/lib/python3.14t/site-packages/binance/ws/websocket_api.py:4
/home/ubuntu/nnf_beta/.venv/lib/python3.14t/site-packages/binance/ws/websocket_api.py:4: DeprecationWarning: websockets.WebSocketClientProtocol is deprecated
from websockets import WebSocketClientProtocol # type: ignore

.venv/lib/python3.14t/site-packages/websockets/legacy/init.py:6
/home/ubuntu/nnf_beta/.venv/lib/python3.14t/site-packages/websockets/legacy/init.py:6: DeprecationWarning: websockets.legacy is deprecated; see https://websockets.readthedocs.io/en/stable/howto/upgrade.html for upgrade instructions
warnings.warn( # deprecated in 14.0 - 2024-11-09

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
--- End ---

This comes from a runtime import in:
binance/ws/websocket_api.py

from websockets import WebSocketClientProtocol

According to the websockets 14+ upgrade notes, WebSocketClientProtocol and
websockets.legacy are deprecated and scheduled for removal.

The warning is triggered on import, even when the class is only used for typing.
This shows up clearly during pytest runs.

A short-term fix could be to guard the import behind typing.TYPE_CHECKING
(or similar), which would remove the runtime warning without changing behavior.

Longer-term, a migration to the new websockets asyncio API may be needed,
but I wanted to report this early since it will eventually become a hard failure.

Environment:

  • python-binance==1.0.34
  • websockets>=14
  • Python 3.12 / 3.13 / 3.14-dev (reproduces across versions)

Happy to open a PR for a minimal fix if this approach is acceptable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions