freshcrate
Home > Frameworks > httpx-ws

httpx-ws

WebSockets support for HTTPX

Description

# HTTPX WS <p align="center"> <em>WebSockets support for HTTPX</em> </p> [![build](https://github.com/frankie567/httpx-ws/workflows/Build/badge.svg)](https://github.com/frankie567/httpx-ws/actions) [![codecov](https://codecov.io/gh/frankie567/httpx-ws/branch/main/graph/badge.svg?token=fL49kIvrj6)](https://codecov.io/gh/frankie567/httpx-ws) [![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors) [![PyPI version](https://badge.fury.io/py/httpx-ws.svg)](https://badge.fury.io/py/httpx-ws) [![Downloads](https://pepy.tech/badge/httpx-ws)](https://pepy.tech/project/httpx-ws) --- **Documentation**: <a href="https://frankie567.github.io/httpx-ws/" target="_blank">https://frankie567.github.io/httpx-ws/</a> **Source Code**: <a href="https://github.com/frankie567/httpx-ws" target="_blank">https://github.com/frankie567/httpx-ws</a> --- ## Installation ```bash pip install httpx-ws ``` ## Features - [x] Sync and async client - [x] Helper methods to send text, binary and JSON data - [x] Helper methods to receive text, binary and JSON data - [x] Automatic ping/pong answers - [x] HTTPX transport to test WebSockets defined in ASGI apps - [x] Automatic keepalive ping - [x] `asyncio` and [Trio](https://trio.readthedocs.io/) support through [AnyIO](https://anyio.readthedocs.io/) ## Contributors ✨ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="http://francoisvoron.com"><img src="https://avatars.githubusercontent.com/u/1144727?v=4?s=100" width="100px;" alt="FranΓ§ois Voron"/><br /><sub><b>FranΓ§ois Voron</b></sub></a><br /><a href="#maintenance-frankie567" title="Maintenance">🚧</a> <a href="https://github.com/frankie567/httpx-ws/commits?author=frankie567" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="http://kousikmitra.github.io"><img src="https://avatars.githubusercontent.com/u/15109533?v=4?s=100" width="100px;" alt="Kousik Mitra"/><br /><sub><b>Kousik Mitra</b></sub></a><br /><a href="https://github.com/frankie567/httpx-ws/commits?author=kousikmitra" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/davidbrochart"><img src="https://avatars.githubusercontent.com/u/4711805?v=4?s=100" width="100px;" alt="David Brochart"/><br /><sub><b>David Brochart</b></sub></a><br /><a href="#platform-davidbrochart" title="Packaging/porting to new platform">πŸ“¦</a> <a href="https://github.com/frankie567/httpx-ws/commits?author=davidbrochart" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://github.com/ysmu"><img src="https://avatars.githubusercontent.com/u/17018576?v=4?s=100" width="100px;" alt="ysmu"/><br /><sub><b>ysmu</b></sub></a><br /><a href="https://github.com/frankie567/httpx-ws/issues?q=author%3Aysmu" title="Bug reports">πŸ›</a></td> <td align="center" valign="top" width="14.28%"><a href="https://samforeman.me"><img src="https://avatars.githubusercontent.com/u/5234251?v=4?s=100" width="100px;" alt="Sam Foreman"/><br /><sub><b>Sam Foreman</b></sub></a><br /><a href="https://github.com/frankie567/httpx-ws/issues?q=author%3Asaforem2" title="Bug reports">πŸ›</a></td> <td align="center" valign="top" width="14.28%"><a href="http://maparent.ca/"><img src="https://avatars.githubusercontent.com/u/202691?v=4?s=100" width="100px;" alt="Marc-Antoine Parent"/><br /><sub><b>Marc-Antoine Parent</b></sub></a><br /><a href="https://github.com/frankie567/httpx-ws/issues?q=author%3Amaparent" title="Bug reports">πŸ›</a> <a href="https://github.com/frankie567/httpx-ws/commits?author=maparent" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="https://www.fastapiexpert.com/"><img src="https://avatars.githubusercontent.com/u/7353520?v=4?s=100" width="100px;" alt="Marcelo Trylesinski"/><br /><sub><b>Marcelo Trylesinski</b></sub></a><br /><a href="https://github.com/frankie567/httpx-ws/issues?q=author%3AKludex" title="Bug reports">πŸ›</a> <a href="#research-Kludex" title="Research">πŸ”¬</a></td> </tr> <tr> <td align="center" valign="top" width="14.28%"><a href="https://lit.link/MtkN1"><img src="https://avatars.githubusercontent.com/u/51289448?v=4?s=100" width="100px;" alt="MtkN1"/><br /><sub><b>MtkN1</b></sub></a><br /><a href="https://github.com/frankie567/httpx-ws/issues?q=author%3AMtkN1" title="Bug reports">πŸ›</a> <a href="#research-MtkN1" title="Research">πŸ”¬</a> <a href="https://github.com/frankie567/httpx-ws/commits?author=MtkN1" title="Code">πŸ’»</a></td> <td align="center" valign="top" width="14.28%"><a href="http://www.tomchristie.com/"><img src="https://avatars.githubusercontent.com/u/647359?v=4?s=100" width=

Release History

VersionChangesUrgencyDate
0.9.0Imported from PyPI (0.9.0)Low4/21/2026
v0.9.0Bump version 0.8.2 β†’ 0.9.0 Breaking changes ---------------- Async exceptions are now wrapped in `ExceptionGroup`. Due to the switch to anyio.AsyncContextManagerMixin for cancellation safety, exceptions that propagate out of the async with block are now wrapped in an ExceptionGroup. **Before:** ```py try: async with aconnect_ws("http://localhost:8000/ws") as ws: data = await ws.receive_text() except WebSocketDisconnect: print("Connection closed") ``` **AfterMedium3/28/2026
v0.8.2Bump version 0.8.1 β†’ 0.8.2 Bug fixes and improvements -------------------------- * ASGIWebSocketTransport: increase the initial receive timeout to 1 second and make it configurable via `initial_receive_timeout` parameter. Fix #123Low11/7/2025
v0.8.1Bump version 0.8.0 β†’ 0.8.1 Bug fixes and improvements -------------------------- * Add Python 3.14 support * ASGI transport: fix cancel scope corruption and allow multiple clients on the same transport (#116). Thanks @davidbrochart πŸŽ‰ * ASGI transport: avoid hanging indefinitely if the server never accepts the connection. Fix #92.Low10/28/2025
v0.8.0Bump version 0.7.2 β†’ 0.8.0 Breaking changes ---------------- * Drop Python 3.9 support Bug fixes and improvements -------------------------- * New class-based API to open clients. [[Documentation](https://frankie567.github.io/httpx-ws/usage/class_based_client/)] Thanks @MtkN1 πŸŽ‰ * Support WebSocket Denial Response in ASGI transport helper. See #84. * Fix websocket disconnection not properly handled in ASGI transport helper. See #97.Low9/20/2025
v0.7.2Bump version 0.7.1 β†’ 0.7.2 Bug fixes --------- * Fix #25: handle broken/disconnected streams more gracefully. Thanks to @runsisi for research and original fix πŸŽ‰Low3/28/2025
v0.7.1Bump version 0.7.0 β†’ 0.7.1 Bug fixes and improvements -------------------------- * Fix `ASGIWebSocketAsyncNetworkStream` implementation to avoid async tasks issues. Thanks @graingert πŸŽ‰Low1/4/2025
v0.7.0Bump version 0.6.2 β†’ 0.7.0 New features ------------ * Allow to pass a custom `session_class` on `connect_ws`/`aconnect_ws` functions. Thanks @GreyElaina πŸŽ‰ Breaking changes ---------------- * Drop Python 3.8 support. Bug fixes and improvements -------------------------- * Fix #29: prevent error when several tasks try to write simultaneously on the same websocket stream. Thanks @GreyElaina πŸŽ‰ * Fix #90: don't use a blocking portal to run the ASGIWebSocketTransport. Thanks @Low12/7/2024
v0.6.2Bump version 0.6.1 β†’ 0.6.2 Bug fixes and improvements -------------------------- * Improve efficiency of `WebSocketSession` by reusing a single thread pool when waiting for messages. Thank you @davidbrochart πŸŽ‰Low10/7/2024
v0.6.1Bump version 0.6.0 β†’ 0.6.1 Bug fixes --------- * Fix (#73) anyio misusages. Thanks @agronholm πŸŽ‰ * Fix (#74) unclosed anyio streams. Thanks @agronholm πŸŽ‰ * Fix (#76) memory leak with non-async WebSocketSession. Thanks @ro-oliveira95 πŸŽ‰Low10/5/2024
v0.6.0Bump version 0.5.2 β†’ 0.6.0 Breaking changes ---------------- * [`AsyncWebSocketSession`](https://frankie567.github.io/httpx-ws/reference/httpx_ws/#httpx_ws.AsyncWebSocketSession) and [`WebSocketSession`](https://frankie567.github.io/httpx-ws/reference/httpx_ws/#httpx_ws.WebSocketSession) no longer accept the `subprotocol` parameter. It's automatically set from the `response` headers (see below). > [!NOTE] > If you only use the `connect_ws` and `aconnect_ws` functions, you don't need tLow4/5/2024
v0.5.2Bump version 0.5.1 β†’ 0.5.2 Bug fixes --------- * Set `anyio` dependency lower bound version to `>4`Low3/19/2024
v0.5.1Bump version 0.5.0 β†’ 0.5.1 Bug fixes and improvements -------------------------- * Always disable automatic keepalive ping when using ASGI transport. Thanks @dmontagu and @Kludex πŸŽ‰ * Bump dependencies: * `httpcore>=1.0.4` - Solves #7, thanks to @tomchristie and @MtkN1 πŸŽ‰Low2/22/2024
v0.5.0Bump version 0.4.3 β†’ 0.5.0 New features ------------ * `asyncio` and [Trio](https://trio.readthedocs.io/) support through [AnyIO](https://anyio.readthedocs.io/) Breaking changes ---------------- * `WebSocketSession` and `AsyncWebSocketSession` are now context managers. If you were using them directly instead of relying on `connect_ws` and `aconnect_ws`, you'll have to adapt your code accordingly: ```py with WebSocketSession(...) as session: ... async with AsyncWebSocketLow2/9/2024
v0.4.3Bump version 0.4.2 β†’ 0.4.3 Bug fixes & improvements ------------------------ * Fix #57: compatibility with `httpx>=0.25.2` * Fix #56: `ASGIWebSocketTransport` returns the correct response from server when opening connection, allowing proper support of subprotocols.Low12/4/2023
v0.4.2Bump version 0.4.1 β†’ 0.4.2 Bug fixes --------- * Fix anyio `start_blocking_portal` import. Thanks @maparent πŸŽ‰ * Fix #40: handle large message buffering * Fix #34: handle subprotocols corrrectly in `ASGIWebSocketTransport`Low9/27/2023
v0.4.1Bump version 0.4.0 β†’ 0.4.1 Bug fixes --------- * Fix import issue with `httpcore>=0.17.3`. Thanks @saforem2 πŸš€Low7/6/2023
v0.4.0Bump version 0.3.1 β†’ 0.4.0 Breaking changes ---------------- * Drop Python 3.7 supportLow6/27/2023
v0.3.1Bump version 0.3.0 β†’ 0.3.1 Bug fixes --------- * Fix #30: ASGI transport now correctly handles server errors and closes the WebSocket instead of hanging. Thanks @ysmu πŸŽ‰Low4/15/2023
v0.3.0Bump version 0.2.6 β†’ 0.3.0 New features ------------ * Add support for subprotocols [[Doccumentation](https://frankie567.github.io/httpx-ws/usage/subprotocols/)] * Thanks @davidbrochart for the idea and feedback πŸ‘Low2/15/2023
v0.2.6Bump version 0.2.5 β†’ 0.2.6 Bug fixes --------- * Fix case where we try to schedule tasks in new threadpool during client closeLow1/3/2023
v0.2.5Bump version 0.2.4 β†’ 0.2.5 Bug fixes --------- * Fix #19: when both todo task and wait task are done in `_wait_until_closed`, make sure to always return the todo task resultLow1/3/2023
v0.2.4Bump version 0.2.3 β†’ 0.2.4 Bug fixes --------- * Fix #15: make sure default HTTPX client is closed.Low12/27/2022
v0.2.3Bump version 0.2.2 β†’ 0.2.3 Improvements ------------ * When closing, stop background threads early when they're stuck in a waiting operationLow11/29/2022
v0.2.2Bump version 0.2.1 β†’ 0.2.2 Improvements ------------ * Automatic keepalive ping mechanismLow11/28/2022
v0.2.1Bump version 0.2.0 β†’ 0.2.1 Improvements ------------ * Handle immediate close from the server in ASGI transport * Improve network errors handlingLow11/28/2022
v0.2.0Bump version 0.1.1 β†’ 0.2.0 Improvements ------------ * Documentation is live ➑️ https://frankie567.github.io/httpx-ws/ * Revamp implementation with a background thread/task receiving messages * Automatic management of ping/pong eventsLow11/27/2022
v0.1.1Bump version 0.1.0 β†’ 0.1.1 Features -------- * Add a `.ping` method. Thanks @kousikmitra πŸŽ‰ Improvements ------------ * Pin lower bound version of `httpx` and `httpcore` dependencies * `httpx>=0.23.1` * `httpcore>=0.16.1`Low11/25/2022
v0.1.0Bump version 0.0.0 β†’ 0.1.0 > ⚠️ This is a very young project. Expect bugs πŸ› Features -------- * `connect_ws` helper to talk to WebSockets synchronously. * `aconnect_ws` helper to talk to WebSockets asynchronously. * `ASGIWebSocketTransport` to test WebSockets in ASGI apps directly.Low11/24/2022

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0