aiohttp
Async HTTP client/server framework for Python with WebSocket support.
3. Used by agents' projects
Dependency in 125 public GitHub projects set up for AI coding agents that we scanned (2.0%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What aiohttp does
aiohttp is one asyncio library that covers both sides of HTTP, a client and a web server, with WebSockets on each side built in. The project behind it dates to 2013.
aiohttp popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How aiohttp is used
- aiohttp is a dependency in 125 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (7.7% of the 1,623 Python ones), #6 of 126 in http clients and networking.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,864; those are left out of every share on this page.
- The most used alternative in our scan is httpx (280 projects).
- Projects that use it most often also use python-dotenv (76.0%), Pydantic (68.0%), Requests (63.2%).
By coding agent
Often used with
aiohttp in practice
Strengths
The same install gives you an HTTP client and a web server. The README's examples cover both: a <code>ClientSession</code> request and a small <code>web.Application</code> with routes.
The README says WebSocket support works out of the box for client and server and "avoids Callback Hell". In its server example, a handler receives messages with <code>async for msg in ws</code> and replies with <code>send_str</code> or <code>send_bytes</code>.
The web server has middlewares, signals and pluggable routing. The docs also list client middleware for customizing request and response processing.
The docs promise that a deprecated public API keeps working for at least a year and a half after the release that deprecates it. Every deprecation raises <code>DeprecationWarning</code>.
Watch out for
The README and docs point people coming from requests to a page titled "why we need so many lines". The session and the response are both opened with <code>async with</code> blocks.
aiodns is optional, but the README calls it "highly recommended for sake of speed". Brotli compression on the client also needs an extra package, Brotli or brotlicffi.
The maintainers write that they sometimes break their own deprecation rule. Their example is a critical bug that cannot be fixed without a major API change.
Fetch a page with ClientSession
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('https://python.org') as response:
print("Status:", response.status)
print("Content-type:", response.headers['content-type'])
html = await response.text()
print("Body:", html[:15], "...")
asyncio.run(main())More about aiohttp
Funding
- GitHub Sponsors: https://github.com/aio-libs
- GitHub Sponsors: https://github.com/asvetlov
- GitHub Sponsors: https://github.com/webknjaz
- GitHub Sponsors: https://github.com/Dreamsorcerer
- Open Collective: https://opencollective.com/aiohttp
- Tidelift: https://tidelift.com/funding/github/pypi/aiohttp
- Own page: https://opencollective.com/aio-libs
- 7 GitHub sponsors
Head to head
- httpx vs aiohttp used together in 32 projects
Packages around it
- python-dotenv: .env file loader
- requests: Synchronous HTTP client
- pydantic: Data validation
- solders: Solana types and bindings
- websockets: WebSocket library
- solana: Solana Python SDK
More in HTTP clients and networking
Alternatives
aiohttp This page
Modern Python HTTP client with async support, replacing the standard requests library.
WebSocket client library for Python with low-level API options.
Get started
Install it.
pip install aiohttpRules for your agent
## aiohttp
- Make requests inside `async with aiohttp.ClientSession() as session:`, open each response with `async with session.get(...) as response:`, and `await response.text()` for the body.
- Do not create a `ClientSession` outside of an event loop; the docs FAQ calls this dangerous.
- Install `aiohttp[speedups]`, or at least `aiodns`, which the docs call highly recommended for DNS speed.
- Run with `python -X dev` during development. aiohttp then uses a strict client parser and adds extra warnings.
- Treat `DeprecationWarning` from aiohttp as a to-do. Deprecated APIs are kept for at least a year and a half, then can go away.
- For servers, register handlers with `app.add_routes([web.get(...)])` and start with `web.run_app(app)`. For WebSockets, create `web.WebSocketResponse()` and `await ws.prepare(request)` before reading messages.
- On 3.14.4 and later, raise `client_max_fields` on `web.Application` if forms can exceed 1000 fields; otherwise they get a 413.