Aiohttp Transport for HTTPX

0.1.12 · active · verified Fri Apr 10

httpx-aiohttp provides an aiohttp-powered transport layer for HTTPX, allowing users to leverage aiohttp's robust asynchronous HTTP capabilities within the familiar HTTPX API. It is currently at version 0.1.12 and is actively maintained with frequent minor releases addressing compatibility and bug fixes.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create an `httpx.AsyncClient` that uses `HttpxAiohttpTransport` to perform an asynchronous GET request to `httpbin.org`.

import asyncio
import httpx
from httpx_aiohttp import HttpxAiohttpTransport

async def main():
    # Initialize the aiohttp-powered transport
    transport = HttpxAiohttpTransport()

    # Create an httpx AsyncClient using the custom transport
    async with httpx.AsyncClient(transport=transport) as client:
        try:
            response = await client.get("https://httpbin.org/get")
            response.raise_for_status() # Raise an exception for HTTP errors
            print(f"Status Code: {response.status_code}")
            print(f"Response JSON: {response.json()}")
        except httpx.HTTPStatusError as e:
            print(f"HTTP error occurred: {e}")
        except httpx.RequestError as e:
            print(f"An error occurred while requesting: {e}")

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →