aiobotocore
aiobotocore is an asyncio-native, mostly feature-complete async wrapper around botocore, enabling non-blocking AWS service calls via aiohttp (with experimental httpx support). Current version is 3.3.0. Releases track botocore closely — minor/patch releases drop frequently (often weekly) to relax or bump the botocore dependency range, with occasional minor releases adding features like socket_factory support in AioConfig.
Warnings
- breaking create_client() MUST be used as an async context manager (async with). Calling it without a context manager and manually closing is unreliable, and since v3.0.0 creating a new ClientSession after the client exits its context is explicitly forbidden and raises an error.
- breaking The aiobotocore[boto3] and aiobotocore[awscli] packaging extras were removed in v3.0.0. Installing them will raise a pip error about unknown extras.
- breaking Credential properties (credentials.access_key, credentials.secret_key, credentials.token) raise NotImplementedError because they do not trigger an async refresh cycle.
- gotcha aiobotocore pins botocore to a narrow version range that changes with every release. Installing aiobotocore alongside boto3, awscli, s3fs, or moto frequently causes pip dependency conflicts because those packages independently pin botocore.
- gotcha get_object() response Body must be consumed inside an async context manager. Reading Body outside of 'async with response["Body"] as stream:' can leave the underlying TCP connection dangling and cause connection pool exhaustion.
- gotcha Paginators are async iterators in aiobotocore. You must use 'async for result in paginator.paginate(...):', NOT a regular 'for' loop. A regular for loop will not await pages and silently yields nothing or raises TypeError.
- deprecated Passing the 'loop' parameter to get_session() is a legacy pattern from pre-asyncio.run() era and is no longer supported. Python's asyncio manages the event loop implicitly.
Install
-
pip install aiobotocore -
pip install aiobotocore boto3 -
pip install 'types-aiobotocore[essential]'
Imports
- get_session
from aiobotocore.session import get_session
- AioSession
from aiobotocore.session import AioSession
- AioConfig
from aiobotocore.config import AioConfig
- AIOHTTPSession
from aiobotocore.httpsession import AIOHTTPSession
- HttpxSession
from aiobotocore.httpxsession import HttpxSession
- ClientError
import botocore.exceptions; botocore.exceptions.ClientError
Quickstart
import asyncio
import os
from aiobotocore.session import get_session
import botocore.exceptions
async def main():
session = get_session()
async with session.create_client(
's3',
region_name='us-east-1',
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
) as client:
try:
response = await client.list_buckets()
for bucket in response.get('Buckets', []):
print(bucket['Name'])
except botocore.exceptions.ClientError as e:
print(f"AWS error: {e.response['Error']['Code']} - {e.response['Error']['Message']}")
except botocore.exceptions.NoCredentialsError:
print('No credentials found')
asyncio.run(main())