Introducing a new way to review your PRs.

Read the announcement

aio-libs / aiobotocore

asyncio support for botocore library using aiohttp

View on GitHub

18 documents · Updated Nov 20, 2026

docs / request-execution

Request execution

Request execution turns an asynchronous client operation into a service call and a common result. It selects the endpoint, builds and signs the HTTP request, sends it through the configured async transport, checks the response when required, and parses the service format into the result returned by the client.

Request lifecycle

The lifecycle joins client-level decisions with endpoint-level work. The operation model describes the service operation and its wire rules, while request context carries choices such as region, authentication, streaming, and checksums through the flow.

This diagram shows how client input becomes a signed exchange and then a normalized result.

flowchart LR
    A[Client operation and parameters] --> B[Operation context]
    B --> C[Endpoint and request serialization]
    C --> D[Authentication and signing]
    D --> E[Async HTTP transport]
    E --> F[Response body and metadata]
    F --> G[Checksum validation]
    G --> H[Protocol parser]
    H --> I[Normalized result or service error]
    H -. retry decision .-> C

Client operation

The client receives an operation name and user parameters. It resolves the operation model, chooses the authentication type, and emits extension hooks before request data is built. These hooks let service rules and callers adjust parameters or handle a call without changing the main path. aiobotocore/client.py

References: aiobotocore/client.py• L353-431

Request construction

Request construction converts validated operation parameters into a request description. Endpoint rules choose the URL and may add headers or signing data. The serializer then maps the parameters to the operation's wire shape, and request preparation adds common HTTP fields such as the user agent. aiobotocore/client.py, aiobotocore/client.py

The request context remains attached to this description. It allows later stages to use the same operation choices without recomputing them.

References: aiobotocore/client.py• L396-413 aiobotocore/client.py• L468-494 aiobotocore/args.py• L90-123

Authentication and signing

Signing adds the service authentication proof to the prepared request. The signer chooses the operation's signature variant from the request context and endpoint signing data. It then obtains the needed credentials or token and applies the signature unless the operation is unsigned. aiobotocore/signers.py

The signing step is part of request creation. A retry creates a fresh request so that the signature and any request-specific values match the new attempt. aiobotocore/endpoint.py

References: aiobotocore/signers.py• L20-92 aiobotocore/signers.py• L94-177 aiobotocore/endpoint.py• L114-139

Async HTTP exchange

The endpoint sends the prepared request through an async HTTP session. The session maintains pooled connections and applies TLS, proxy, timeout, and streaming behavior. The default AIOHTTPSession uses aiohttp; the optional HttpxSession provides the same endpoint contract for an HTTPX and AnyIO-based runtime. aiobotocore/endpoint.py, aiobotocore/httpsession.py, aiobotocore/httpxsession.py

The transport returns an async AWS response wrapper. Non-streaming bodies are read before the call continues. Streaming outputs keep the network body open for the caller or for an event-stream parser. See endpoint and HTTP transport for the transport boundary and its backend behavior.

References: aiobotocore/endpoint.py• L183-227 aiobotocore/httpsession.py• L266-333 aiobotocore/httpxsession.py• L433-520 aiobotocore/awsrequest.py• L5-41

Response processing

Response processing turns backend-specific HTTP data into the service result expected by the client. It keeps status, headers, operation context, and body together until checksum checks and protocol parsing finish.

Response body handling

The endpoint makes an HTTP response dictionary with headers, status, context, and a body. Error bodies are read at once so the parser can identify the service error. Successful streaming bodies stay as async streams, which lets large results and event streams move without one full in-memory read. aiobotocore/endpoint.py

Async response bodies support reads, iteration, line iteration, and async close across both supported HTTP backends. They also check the declared content length when the stream ends and map read failures to common async response errors. aiobotocore/response.py, aiobotocore/response.py

References: aiobotocore/endpoint.py• L30-66 aiobotocore/response.py• L36-101 aiobotocore/response.py• L131-185 aiobotocore/response.py• L187-285

Checksum processing

Checksum processing protects request and response bodies when the operation asks for it. A request checksum can be placed in a header or added as a trailing value on a chunked body. A response checksum validates either the complete byte body or each streamed read before the result is trusted. aiobotocore/httpchecksum.py

Checksum metadata is stored in response context after a successful check. A checksum that does not match raises a checksum error instead of returning corrupted data. See protocol parsing and checksums for protocol-specific checksum rules.

References: aiobotocore/client.py• L406-431 aiobotocore/endpoint.py• L212-220 aiobotocore/httpchecksum.py• L73-109 aiobotocore/httpchecksum.py• L148-204

Protocol parsing

Protocol parsing maps the response body and headers to the output shape defined by the operation model. A protocol is the service wire format, such as JSON, XML, query, or RPC CBOR. The parser also adds common response metadata such as HTTP status and normalized headers. aiobotocore/parsers.py

Event-stream outputs use a two-part result. The parser reads the initial response and returns an async event stream for later records. A missing initial response is a protocol error. aiobotocore/parsers.py, aiobotocore/parsers.py

The parser family is selected from the operation's resolved protocol. This keeps the client result shape stable while allowing each service protocol to decode its own wire data. aiobotocore/endpoint.py, aiobotocore/parsers.py

References: aiobotocore/parsers.py• L29-71 aiobotocore/parsers.py• L121-147 aiobotocore/parsers.py• L154-191 aiobotocore/parsers.py• L200-207 aiobotocore/endpoint.py• L229-251

Service result

The client receives a parsed response after endpoint processing. For an HTTP error, the parsed error code selects the service exception class and the client raises it after the response hooks run. A successful status returns the parsed result with response metadata. aiobotocore/client.py

Retry decisions use the response or the caught exception. When a retry is requested, the endpoint waits without blocking the async runtime, resets a request stream, and sends a newly signed request. aiobotocore/endpoint.py, aiobotocore/endpoint.py

References: aiobotocore/client.py• L435-466 aiobotocore/endpoint.py• L122-153 aiobotocore/endpoint.py• L272-305 aiobotocore/_endpoint_helpers.py• L9-37

Extension boundaries

The execution path exposes named event hooks at the points where service behavior or caller policy can change the request or inspect the result. The hooks preserve a common lifecycle while allowing endpoint discovery, retries, signing, compression, and service-specific behavior to participate.

The main boundaries are:

  • Parameter input before serialization.
  • Endpoint selection before request preparation completes.
  • Request creation and signing before transport sends bytes.
  • The retry decision after a response or transport error.
  • Response receipt before parsing and after the client has a parsed result. aiobotocore/client.py, aiobotocore/endpoint.py, aiobotocore/endpoint.py

These boundaries are also the main way service-specific behavior stays outside the general request path. A handler may provide a response before transport runs, but normal calls continue through signing, transport, checksum handling, and parsing.

References: aiobotocore/client.py• L496-519 aiobotocore/client.py• L415-441 aiobotocore/endpoint.py• L95-112 aiobotocore/endpoint.py• L164-181

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to operation context must remain compatible with endpoint rules, signer choice, checksum resolution, and per-request timeout handling.
  • Changes to stream_output must preserve the contract between transport buffering, response body ownership, checksum validation, and event-stream parsing.
  • Changes to the protocol parser map must cover every protocol named by service models and preserve response metadata behavior.
  • Changes to retry handling must keep request bodies repeatable and must create a new signature for each attempt.
  • Changes to event names or event payloads must preserve the request and response hooks used by service handlers and caller extensions.

Important failure modes

TriggerConsequenceGuard
Endpoint rules produce an invalid URL or no usable endpointThe call fails before the HTTP exchangeValidate endpoint configuration and service endpoint rules.
The selected signature needs unavailable credentials, a token, or a regionRequest signing fails and no service result is returnedKeep auth context and credential or token resolution aligned with the operation model.
A request or response checksum does not match its bodyA checksum error stops the result from being acceptedPreserve checksum headers and consume the body through the checksum-aware path.
A streaming response ends early or the network read times outThe caller receives a stream error or read-timeout errorRead and close async bodies through the response interface and honor content length.
The service returns an HTTP status of 300 or higherThe parsed service error becomes a typed client exceptionKeep error bodies available to the parser and retain the service error code.
A retry is requested for a streamed request body that cannot resetThe retry can send an incomplete or unusable bodyUse a resettable request stream when the operation can retry.

Key files

FileWhy to read it
aiobotocore/client.pyDefines the client-facing operation path from parameters to request creation, hooks, retries, and the final service result.
aiobotocore/args.pyShows how a client receives its serializer, signer, endpoint, and protocol parser.
aiobotocore/endpoint.pyCoordinates request creation, transport, response conversion, retry attempts, checksums, and parsing.
aiobotocore/signers.pyExplains how operation and endpoint context become request authentication.
aiobotocore/parsers.pyShows the common response contract and the supported protocol parser families.
aiobotocore/httpchecksum.pyDefines the request and response checksum boundary for byte and streaming bodies.
aiobotocore/response.pyDefines the async response body contract and common stream error behavior.
aiobotocore/httpsession.pyShows the default async transport boundary for connection pooling, TLS, proxies, and timeouts.
aiobotocore/httpxsession.pyShows the alternate transport boundary for the HTTPX and AnyIO runtime.