How aio-libs/aiohttp works
aiohttp is an asyncio HTTP client/server framework, with WebSocket support on both sides. Its client workflow builds a request, obtains a connection, exchanges HTTP data, and exposes a response; its server workflow accepts a request, dispatches a route through middleware to a handler, and sends a response. WebSocket handling branches from HTTP upgrade on each side. The tree and README establish these capabilities; sampled excerpts chiefly confirm client request/response, connector, and frame-processing responsibilities, so uncertain internal links are omitted.
Main entry points: client.py Client session · client_reqrep.py Client request/response · web_app.py Application and routes · web_protocol.py Server protocol
Components 26
HTTP client
- Client session
aiohttp/client.py - Client request/response
aiohttp/client_reqrep.py - Connection pool
aiohttp/connector.py - Client protocol
aiohttp/client_proto.py - Digest middleware
aiohttp/client_middleware_digest_auth.py
HTTP server
- Application and routes
aiohttp/web_app.py - Server middleware
aiohttp/web_middlewares.py - URL dispatcher
aiohttp/web_urldispatcher.py - Server request
aiohttp/web_request.py - Server response
aiohttp/web_response.py - Server protocol
aiohttp/web_protocol.py - Server lifecycle
aiohttp/web_server.py
HTTP and streams
- HTTP parser
aiohttp/http_parser.py - HTTP writer
aiohttp/http_writer.py - Async streams
aiohttp/streams.py
WebSocket
- Client WebSocket
aiohttp/client_ws.py - Server WebSocket
aiohttp/web_ws.py - Frame reader
aiohttp/_websocket/reader.py - Frame writer
aiohttp/_websocket/writer.py
Request support
- Payload encoding
aiohttp/payload.py - Multipart forms
aiohttp/multipart.py - Cookie jar
aiohttp/cookiejar.py
Other components
- Application code
- Remote HTTP peer
- Incoming HTTP peer
- Route handler
Connections 31
- Application code → Client session: requests through
- Client session → Client request/response: creates and sends
- Client session → Connection pool: acquires connection
- Client request/response → Connection pool: sends request
- Connection pool → Remote HTTP peer: exchanges transport data
- Client protocol → HTTP parser: parses response data
- HTTP parser → Async streams: feeds body bytes
- Client request/response → Payload encoding: encodes request body
- Client session → Cookie jar: manages cookies
- Digest middleware → Client session: middleware integration
- Incoming HTTP peer → Server lifecycle: connects to
- Server lifecycle → Server protocol: serves protocol
- Server protocol → HTTP parser: parses request data
- HTTP parser → Server request: provides parsed request
- Server protocol → Application and routes: dispatches request
- Application and routes → Server middleware: applies middleware
- Application and routes → URL dispatcher: resolves route
- URL dispatcher → Route handler: invokes handler
- Route handler → Server response: returns response
- Server protocol → HTTP writer: writes response
- Server response → HTTP writer: serializes response
- HTTP writer → Remote HTTP peer: sends HTTP data
- Application and routes → Server WebSocket: supports upgrade handler
- Client session → Client WebSocket: initiates upgrade
- Client WebSocket → Frame reader: reads frames
- Client WebSocket → Frame writer: writes frames
- Server WebSocket → Frame reader: reads frames
- Server WebSocket → Frame writer: writes frames
- Frame reader → Async streams: queues messages
- Frame writer → Remote HTTP peer: sends frames
- Client request/response → Multipart forms: parses disposition