PyQwest
PyQwest is a modern Python HTTP client built on the high-performance Rust library `reqwest`. It offers support for advanced HTTP features, including bidirectional streaming, HTTP/2, and HTTP/3. It provides both asynchronous and synchronous client interfaces and aims for a fully-typed, Pythonic API. The current version is 0.4.1. Releases are made on an as-needed basis, often to incorporate updates from the underlying `reqwest` library or to add new features.
Warnings
- gotcha PyQwest is a Rust-based library. If pre-built wheels are not available for your specific platform and Python version, you will need the Rust toolchain installed for `pip` to build it from source.
- breaking If you were previously passing custom `httpx.AsyncClient` or `httpx.Client` sessions directly to clients that now internally use `pyqwest` (e.g., `connect-python` v0.8.0+), you will need to migrate to passing `pyqwest.HTTPTransport` or `pyqwest.SyncHTTPTransport` instances, or a `pyqwest.Client`/`pyqwest.SyncClient` directly.
- gotcha The `pyqwest` library is distinct from `pyreqwest`. While both are Python HTTP clients based on the Rust `reqwest` library, they are separate projects with different APIs and development teams. Ensure you are importing and using the correct library.
Install
-
pip install pyqwest
Imports
- Client
from pyqwest import Client
- SyncClient
from pyqwest import SyncClient
- PyQwestTransport
from pyqwest.httpx import PyQwestTransport
- AsyncPyQwestTransport
from pyqwest.httpx import AsyncPyQwestTransport
Quickstart
import asyncio
from pyqwest import Client, SyncClient
async def async_example():
client = Client()
response = await client.get("https://httpbin.org/get")
print(f"Async Response Status: {response.status}")
print(f"Async Response Body Length: {len(await response.content())}")
def sync_example():
client = SyncClient()
response = client.get("https://httpbin.org/get")
print(f"Sync Response Status: {response.status}")
print(f"Sync Response Body Length: {len(response.content())}")
if __name__ == "__main__":
print("Running async example...")
asyncio.run(async_example())
print("\nRunning sync example...")
sync_example()