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 / asynchronous-service-features

Asynchronous service features

Asynchronous service features extend the botocore client model for service interactions that need more than one response or more than one request. They let an engineer page through large result sets, wait for a modeled service state, or consume a streamed response with await and async for while keeping botocore's service models, names, errors, and response shapes.

Service interaction model

The async client keeps the normal service operation as its basic unit. Higher-level features use that operation as a controlled building block: a paginator calls it again with a continuation token, a waiter calls it again after a delay, and an event stream turns one response body into a sequence of events.

The client chooses the async behavior that matches its HTTP session. The default session uses asyncio; the httpx session also supports AnyIO runtimes such as Trio. This choice is internal to the feature and does not change the botocore-facing service contract. aiobotocore/client.py• L573-671, aiobotocore/_async_primitives.py• L8-16

The relationship between the three features is shown below.

flowchart LR
    A[Async service operation] --> B[Paginator]
    A --> C[Waiter]
    A --> D[Event stream response]
    B --> E[Pages or selected items]
    C --> F[Ready state or waiter error]
    D --> G[Parsed events or stream error]

Multi-request result retrieval

Pagination turns a service operation that returns one page into an asynchronous sequence of pages. The paginator follows the service's modeled input and output tokens, preserves botocore pagination options such as page size and maximum items, and exposes page selection and full-result aggregation when the caller needs a simpler result.

A caller consumes pages with async for. The paginator can also search each page with a JMESPath expression or return iterators for modeled result fields. A starting token lets a caller resume from a prior bounded result. A repeated service token is treated as a pagination error instead of creating an endless request loop. See Paginators and waiters for the detailed pagination contract.

References: aiobotocore/client.py• L573-645 aiobotocore/paginate.py• L13-99 aiobotocore/paginate.py• L101-168 tests/test_basic_s3.py• L87-148

Long-running state observation

A waiter turns a modeled target state into one asynchronous operation. It invokes the service operation, checks the response against ordered acceptors, and sleeps between attempts until it reaches success or a terminal failure. This gives callers a service-aware way to wait for work such as resource creation without writing their own polling loop.

Waiters accept per-call delay and attempt limits through the botocore-compatible WaiterConfig shape. They return the successful response and raise WaiterError for a service error, a modeled failure state, or an exhausted attempt limit. Their sleep uses the runtime selected by the client's HTTP session. See Paginators and waiters for the state and retry details.

References: aiobotocore/client.py• L647-671 aiobotocore/waiter.py• L25-85 aiobotocore/waiter.py• L88-170 tests/test_waiter.py• L48-74

Incremental event delivery

An event stream represents a response whose body contains a sequence of service events rather than one complete result. The async stream reads available chunks, joins them into complete protocol events, parses each event with the service output shape, and yields parsed values through async for.

The stream may provide an initial response before later events. A successful event becomes a normal parsed service value; a non-success event raises EventStreamError, and a missing initial response raises NoInitialResponseError. Synchronous iteration is not supported because consuming the stream must yield control while data arrives. See Event streams for the stream lifecycle and event types.

References: aiobotocore/parsers.py• L39-76 aiobotocore/eventstream.py• L9-50 tests/test_eventstreams.py• L49-92

Botocore compatibility boundary

The higher-level features reuse botocore's models and public concepts instead of defining a separate service API. Service names map to the same operation, paginator, and waiter definitions. Generated documentation is attached to the async methods so callers still see the service-specific contract.

The async boundary changes how work is consumed, not what the service means. A normal client operation is awaited. A multi-page or streamed result is consumed with an async iterator. A waiter is awaited as one long-running action. Response parsing still adds the normal response metadata for ordinary responses, while event-stream responses retain their event-specific shape. aiobotocore/client.py• L597-645, aiobotocore/parsers.py• L39-71

Change checklist

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

  • When client operation construction changes, check that paginator and waiter factories still receive the same botocore operation names and async client methods.
  • When HTTP session backends change, check both runtime sleep behavior and iterator fan-out behavior for asyncio and AnyIO paths.
  • When response parsing changes, check that event-stream responses avoid ordinary response metadata decoration and still use the service output shape.
  • When pagination token or result rules change, check resume tokens, bounded results, full-result aggregation, and repeated-token protection together.
  • When waiter models or error handling change, check success, terminal failure, service error, and attempt-limit outcomes as one contract.

Important failure modes

TriggerConsequenceGuard
A service returns the same continuation token twicePagination can loop over the same page or stop with incomplete workThe page iterator raises PaginationError when a token repeats.
A bounded pagination run reaches a page boundaryA later run can restart at the wrong item or duplicate resultsThe paginator returns a resume token and accepts it as StartingToken.
A waiter receives an unmatched service errorThe caller can mistake a failed resource operation for a pending oneThe waiter treats valid waiter errors as terminal WaiterError results.
A waiter reaches its attempt limit without successThe call ends without a ready resourceWaiterConfig.MaxAttempts and the modeled limit produce WaiterError.
An event stream has no initial responseThe caller cannot establish the stream's expected first responseThe stream raises NoInitialResponseError.
An event stream carries a non-success eventThe caller can process an invalid event as normal dataEvent parsing raises EventStreamError for non-200 event responses.

Key files

FileWhy to read it
aiobotocore/client.pyShows how the async client exposes paginator and waiter factories while preserving botocore naming and documentation.
aiobotocore/paginate.pyShows the page, result, resume, and full-result behavior behind asynchronous pagination.
aiobotocore/waiter.pyShows how modeled polling becomes an awaitable action with runtime-aware sleep and botocore-compatible errors.
aiobotocore/eventstream.pyShows how streamed response chunks become parsed asynchronous events.
aiobotocore/parsers.pyShows where ordinary response parsing hands event-stream responses to the async stream.
aiobotocore/_async_primitives.pyShows how the HTTP session selects asyncio or AnyIO behavior.
docs/paginators-and-waiters.mdChild page for the detailed pagination and waiter contracts.
docs/event-streams.mdChild page for the detailed streamed-response contract.