Knowledge Base updated: 2026-11-22
aiohttp knowledge base
Orientation
aiohttp is an asyncio-based HTTP client and web-server framework. Its main implementation lives in aiohttp/, with distinct client, web-server, protocol/streaming, WebSocket, payload, and test-support layers.
Client request state is coordinated by ClientSession, connectors, cookie jars, and response objects. Server state is coordinated by Application, routers, request handlers, runners, and sites. Shared transport state lives in protocols, streams, parsers, writers, and WebSocket reader/writer machinery.
flowchart TD
App[Application code]
Client[ClientSession]
Connector[TCPConnector]
ClientReq[ClientRequest / ClientResponse]
Cookie[CookieJar]
Server[web.Application]
Router[UrlDispatcher]
Handler[Request handler]
Runner[AppRunner / Site]
Protocol[HTTP protocol]
Streams[StreamReader / DataQueue]
Parser[HTTP parser / writer]
WS[WebSocket engine]
Transport[asyncio transport]
App --> Client
Client --> Connector
Client --> ClientReq
Client --> Cookie
Connector --> Protocol
Server --> Router
Router --> Handler
Runner --> Server
Protocol --> Streams
Protocol --> Parser
Parser --> Transport
ClientReq --> WS
Handler --> WS
WS --> Transport
Glossary
- ClientSession — client-side owner of request defaults, connector use, cookies, middleware, and tracing.
- Connector — pool and lifecycle manager for outbound transports, DNS resolution, TLS, and proxy connections.
- Application — web-server container for routes, middleware, signals, and lifecycle state.
- Runner/Site — deployment-layer objects that bind an application to listening sockets and manage shutdown.
- Payload — adapter that serializes application values into HTTP request or response body bytes.
Routing table
- aiohttp/client.py, aiohttp/client_reqrep.py, aiohttp/client_exceptions.py -> docs/http-client.md
- aiohttp/client.py, aiohttp/client_reqrep.py -> docs/client-request-lifecycle.md
- aiohttp/connector.py, aiohttp/resolver.py, aiohttp/client_proto.py -> docs/client-connectivity-and-proxies.md
- aiohttp/cookiejar.py, aiohttp/client_middlewares.py, aiohttp/tracing.py -> docs/client-state-and-interception.md
- aiohttp/web_app.py, aiohttp/web_protocol.py, aiohttp/web_runner.py -> docs/web-server.md
- aiohttp/web_protocol.py, aiohttp/web_request.py, aiohttp/web_middlewares.py -> docs/server-request-processing.md
- aiohttp/web_urldispatcher.py, aiohttp/web_response.py, aiohttp/web_fileresponse.py -> docs/server-routing-and-responses.md
- aiohttp/web_app.py, aiohttp/web_runner.py, aiohttp/web.py, aiohttp/worker.py -> docs/server-lifecycle-and-deployment.md
- aiohttp/client_ws.py, aiohttp/web_ws.py,
aiohttp/_websocket/**-> docs/websocket-support.md aiohttp/_websocket/**, aiohttp/http_websocket.py -> docs/websocket-protocol-engine.md- aiohttp/client_ws.py, aiohttp/web_ws.py -> docs/websocket-endpoint-lifecycles.md
- aiohttp/base_protocol.py, aiohttp/http_parser.py, aiohttp/http_writer.py, aiohttp/streams.py -> docs/http-transport.md
- aiohttp/http_parser.py, aiohttp/http_writer.py,
aiohttp/_http_parser.pyx-> docs/http-parsing-and-writing.md - aiohttp/streams.py, aiohttp/base_protocol.py -> docs/stream-flow-control.md
- aiohttp/payload.py, aiohttp/formdata.py, aiohttp/multipart.py, aiohttp/cookiejar.py -> docs/http-data-handling.md
- aiohttp/payload.py, aiohttp/payload_streamer.py, aiohttp/formdata.py, aiohttp/multipart.py -> docs/payloads-forms-and-multipart.md
- aiohttp/cookiejar.py, aiohttp/cookie_helpers.py, aiohttp/compression_utils.py, aiohttp/helpers.py -> docs/cookies-compression-and-utilities.md
- aiohttp/log.py, aiohttp/tracing.py, aiohttp/test_utils.py, aiohttp/pytest_plugin.py -> docs/observability-and-test-support.md