Type annotations for aioboto3

15.5.0 · active · verified Thu Apr 09

types-aioboto3 provides comprehensive type annotations (stubs) for the aioboto3 library, enabling static type checking for asynchronous AWS client operations with tools like Mypy. It's generated by mypy-boto3-builder and aligns with aioboto3 and AWS service changes. The current version is 15.5.0, with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate `types-aioboto3` for static type checking with an `aioboto3` S3 client. It shows how to import and apply `S3Client` and `BucketTypeDef` to enhance code clarity, enable IDE autocompletion, and catch potential errors at development time.

import aioboto3
import asyncio
from types_aioboto3_s3.client import S3Client
from types_aioboto3_s3.type_defs import BucketTypeDef

async def list_s3_buckets_typed():
    session = aioboto3.Session()
    async with session.client("s3") as client:
        # Type hint the client to enable autocompletion and static checks
        client: S3Client
        
        response = await client.list_buckets()
        
        # Type hint the list of buckets for better type safety
        buckets: list[BucketTypeDef] = response.get("Buckets", [])
        
        if not buckets:
            print("No S3 buckets found or access denied.")
            return

        print("S3 Buckets:")
        for bucket in buckets:
            print(f"  - {bucket['Name']}")

async def main():
    # aioboto3 uses standard AWS credential chain (e.g., environment variables, 
    # ~/.aws/credentials, IAM roles). No hardcoded keys are needed here.
    await list_s3_buckets_typed()

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

view raw JSON →