This module wraps aiohttp.ClientSession
so that it can be used with APIs such as:
- HTTP request
import aiohttp_client async with aiohttp_client.Client() as client: r = await client.get("https://httpbin.org/get") # without "async with" print(r.json()) # without "await"
- HTTP request (Stream)
import aiohttp_client async with aiohttp_client.Client() as client: async with client.stream("GET", "https://httpbin.org/get") as resp: # aiohttp conventional API print(await resp.json())
- 🚧 WIP: WebSocket
import aiohttp_client async with aiohttp_client.Client() as client: async for ws in client.ws_connect("wss://echo.websoket.events"): # Reconnection print(await ws.recv())
The purpose of this API is to...
- 1. and 2. aim to provide an API similar to
httpx
(AsyncClient
). When you make HTTP requests in Python, isn't it mostly to get the HTTP (REST) API? In that case, this API makes sense. - 3. provides a reconnect API similar to
websockets
. Users often want to be able to easily reconnect to WebSocket connections.