aiohttp
Async HTTP client/server framework for asyncio. Provides both a client (ClientSession) and a web server (web.Application). Current version is 3.13.3 (Jan 2026). Has removed several long-deprecated parameters that LLMs still generate.
Warnings
- breaking timeout= parameter must be aiohttp.ClientTimeout, not int/float. Passing timeout=30 raises AttributeError: 'int' object has no attribute 'total' at request time, not at session creation. The error is confusing and delayed.
- breaking loop= parameter removed from ClientSession, TCPConnector, and all other aiohttp objects. Was deprecated for years; removed in 3.9. LLM-generated code from older tutorials passes loop=asyncio.get_event_loop().
- breaking read_timeout and conn_timeout constructor parameters removed from ClientSession. Replaced by ClientTimeout.
- breaking verify_ssl=, ssl_context=, and fingerprint= parameters deprecated in request methods. Replaced by unified ssl= parameter.
- deprecated app.loop, request.loop, client.loop, connector.loop properties deprecated and scheduled for removal in aiohttp 4.0.
- gotcha Creating ClientSession outside of an async context (e.g. at module level or in __init__) raises DeprecationWarning and will raise RuntimeError in a future version.
- gotcha Response body must be consumed before the response context manager exits, or the connection is left in a broken state. await resp.json() / await resp.text() / await resp.read() must be called inside the async with block.
Install
-
pip install aiohttp -
pip install aiohttp[speedups]
Imports
- ClientSession
import aiohttp async with aiohttp.ClientSession() as session: async with session.get('https://example.com') as resp: data = await resp.json() - ClientTimeout
timeout = aiohttp.ClientTimeout(total=30) async with aiohttp.ClientSession(timeout=timeout) as session: ...
Quickstart
import aiohttp
import asyncio
async def main():
timeout = aiohttp.ClientTimeout(total=30)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get('https://httpbin.org/get') as resp:
print(resp.status)
data = await resp.json()
print(data)
asyncio.run(main())
# Server
from aiohttp import web
async def handle(request):
return web.Response(text='Hello')
app = web.Application()
app.add_routes([web.get('/', handle)])
web.run_app(app)