aioboto3

15.5.0 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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())

view raw JSON →