aioboto3

raw JSON →
15.5.0 verified Tue May 12 auth: no python install: verified quickstart: stale

aioboto3 is an asynchronous wrapper for boto3, the Amazon Web Services (AWS) SDK for Python. It allows developers to interact with AWS services using Python's `async/await` syntax, leveraging the `aiobotocore` library for its asynchronous backend. This enables non-blocking I/O operations with AWS, ideal for modern async applications. The current version is 15.5.0, with frequent releases often aligned with updates to its underlying dependencies.

pip install aioboto3
error ModuleNotFoundError: No module named 'aioboto3'
cause The 'aioboto3' library is not installed in the Python environment.
fix
pip install aioboto3
error AttributeError: 'ResourceCreatorContext' object has no attribute 'Table'
cause The 'resource' method in 'aioboto3' is asynchronous and needs to be awaited.
fix
dynamodb = await aioboto3.Session().resource('dynamodb')
error AttributeError: module 'aiobotocore' has no attribute 'AioSession'
cause The 'AioSession' attribute is not present in the 'aiobotocore' module, possibly due to version incompatibility.
fix
Ensure compatible versions of 'aioboto3' and 'aiobotocore' are installed, or downgrade 'aioboto3' to a version where 'AioSession' is available.
error AttributeError: 'ClientCreatorContext' object has no attribute 'invoke_endpoint'
cause The 'client' method in 'aioboto3' is asynchronous and needs to be awaited.
fix
sagemaker_client = await aioboto3.Session().client('sagemaker-runtime')
error RuntimeWarning: coroutine '...' was never awaited
cause An asynchronous function (coroutine) was called, but its execution was not properly initiated using the `await` keyword or by `asyncio.run()`, meaning the coroutine object was created but never executed.
fix
Ensure all calls to async functions within an async context are prefixed with await. If calling from synchronous code, wrap the coroutine call with asyncio.run().
breaking Breaking Change in v9: Direct calls to `aioboto3.resource()` and `aioboto3.client()` are no longer available. You must first create a `Session` object and then use `session.client()` or `session.resource()`.
fix Replace `aioboto3.client('service')` with `session = aioboto3.Session(); async with session.client('service') as client:`
breaking Breaking Change in v9/v8.0.0+: `client` and `resource` methods (obtained from a session) must now be used as asynchronous context managers (`async with`). This change aligns with `aiobotocore` 1.0.1+ behavior.
fix Ensure all `session.client()` and `session.resource()` calls are wrapped in an `async with` statement, e.g., `async with session.client('s3') as s3_client:`.
breaking Breaking Change in v11: The `S3Transfer` configuration passed into S3 `upload_file` and `download_file` methods has been updated to match `boto3`'s behavior, which might require adjustments if you were passing custom transfer configurations.
fix Review S3 `upload_file` and `download_file` calls for custom `S3Transfer` configurations and adapt them to the `boto3`-aligned structure.
gotcha Service-specific resource objects (e.g., `s3.Bucket`, `dynamo_resource.Table`) must be `await`ed when instantiated, as their creation is an asynchronous operation.
fix Always use `await` when getting a specific resource object, e.g., `bucket = await s3_resource.Bucket('mybucket')` or `table = await dynamodb_resource.Table('my_table')`.
gotcha For long-running processes like web servers, directly using `async with session.client(...)` per request can introduce overhead. For persistent clients, an `AsyncExitStack` or similar pattern is recommended to manage the context manager lifecycle.
fix For persistent clients in web servers, manage client/resource lifecycle using `AsyncExitStack` (e.g., in FastAPI's startup/shutdown events) to ensure clients are opened once and properly closed.
gotcha aioboto3 could not find AWS credentials. This often manifests as `botocore.exceptions.NoCredentialsError: Unable to locate credentials` when attempting to interact with AWS services.
fix Ensure AWS credentials are correctly configured in your environment. This can be done via environment variables (e.g., `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`), shared credential files (`~/.aws/credentials`), or IAM roles (for EC2 instances or ECS tasks).
gotcha Unable to locate AWS credentials. Ensure your AWS credentials are configured via environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY), shared credentials file (~/.aws/credentials), or IAM roles/profiles.
fix Configure AWS credentials in your environment. Refer to the AWS documentation on configuring the AWS CLI and SDKs for detailed instructions.
pip install aioboto3[s3cse]
python os / libc variant status wheel install import disk
3.10 alpine (musl) aioboto3 wheel - 1.08s 60.2M
3.10 alpine (musl) s3cse wheel - 1.08s 76.4M
3.10 alpine (musl) aioboto3 - - 1.00s 60.5M
3.10 alpine (musl) s3cse - - 1.00s 75.7M
3.10 slim (glibc) aioboto3 wheel 7.9s 0.81s 62M
3.10 slim (glibc) s3cse wheel 9.0s 0.86s 79M
3.10 slim (glibc) aioboto3 - - 0.81s 63M
3.10 slim (glibc) s3cse - - 0.80s 78M
3.11 alpine (musl) aioboto3 wheel - 1.24s 64.2M
3.11 alpine (musl) s3cse wheel - 1.25s 81.0M
3.11 alpine (musl) aioboto3 - - 1.34s 64.6M
3.11 alpine (musl) s3cse - - 1.35s 80.3M
3.11 slim (glibc) aioboto3 wheel 6.6s 1.12s 67M
3.11 slim (glibc) s3cse wheel 7.6s 1.13s 83M
3.11 slim (glibc) aioboto3 - - 1.05s 67M
3.11 slim (glibc) s3cse - - 1.08s 83M
3.12 alpine (musl) aioboto3 wheel - 1.38s 55.7M
3.12 alpine (musl) s3cse wheel - 1.51s 72.4M
3.12 alpine (musl) aioboto3 - - 1.46s 56.1M
3.12 alpine (musl) s3cse - - 1.46s 71.7M
3.12 slim (glibc) aioboto3 wheel 5.1s 1.37s 58M
3.12 slim (glibc) s3cse wheel 5.9s 1.50s 75M
3.12 slim (glibc) aioboto3 - - 1.42s 59M
3.12 slim (glibc) s3cse - - 1.40s 74M
3.13 alpine (musl) aioboto3 wheel - 1.38s 55.1M
3.13 alpine (musl) s3cse wheel - 1.35s 71.8M
3.13 alpine (musl) aioboto3 - - 1.40s 55.4M
3.13 alpine (musl) s3cse - - 1.42s 71.0M
3.13 slim (glibc) aioboto3 wheel 4.9s 1.35s 57M
3.13 slim (glibc) s3cse wheel 5.5s 1.30s 74M
3.13 slim (glibc) aioboto3 - - 1.39s 58M
3.13 slim (glibc) s3cse - - 1.38s 73M
3.9 alpine (musl) aioboto3 wheel - 0.92s 60.4M
3.9 alpine (musl) s3cse wheel - 1.03s 77.4M
3.9 alpine (musl) aioboto3 - - 0.86s 60.4M
3.9 alpine (musl) s3cse - - 0.87s 76.3M
3.9 slim (glibc) aioboto3 wheel 9.3s 0.94s 63M
3.9 slim (glibc) s3cse wheel 10.5s 1.00s 80M
3.9 slim (glibc) aioboto3 - - 0.78s 63M
3.9 slim (glibc) s3cse - - 0.80s 79M

This quickstart demonstrates creating an asynchronous DynamoDB resource, creating a table (if it doesn't exist), inserting an item, querying it, and finally deleting the table. Ensure your AWS credentials and default region are configured in your environment (e.g., via `~/.aws/credentials` or environment variables like `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_DEFAULT_REGION`).

import asyncio
import os
from aioboto3 import Session
from boto3.dynamodb.conditions import Key

async def main():
    aws_region = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
    session = Session()
    async with session.resource('dynamodb', region_name=aws_region) as dynamodb_resource:
        table_name = 'my_async_table'
        # Check if table exists, create if not (simplified for quickstart)
        try:
            await dynamodb_resource.Table(table_name).wait_until_exists()
            print(f"Table '{table_name}' already exists.")
        except Exception:
            print(f"Creating table '{table_name}'...")
            table = await dynamodb_resource.create_table(
                TableName=table_name,
                KeySchema=[
                    {'AttributeName': 'pk', 'KeyType': 'HASH'}
                ],
                AttributeDefinitions=[
                    {'AttributeName': 'pk', 'AttributeType': 'S'}
                ],
                BillingMode='PAY_PER_REQUEST'
            )
            await table.wait_until_exists()
            print(f"Table '{table_name}' created successfully.")
            table = await dynamodb_resource.Table(table_name)

        table = await dynamodb_resource.Table(table_name)
        
        print("Putting item...")
        await table.put_item(
            Item={'pk': 'test1', 'data': 'async_data_value'}
        )
        print("Item put.")

        print("Querying item...")
        result = await table.query(
            KeyConditionExpression=Key('pk').eq('test1')
        )
        print("Query result:", result['Items'])

        # Clean up (optional, for demonstration)
        print(f"Deleting table '{table_name}'...")
        await table.delete()
        await table.wait_until_not_exists()
        print(f"Table '{table_name}' deleted.")

if __name__ == '__main__':
    asyncio.run(main())