boto3-stubs Type Annotations for AWS SDK for Python

1.42.78 · active · verified Sat Mar 28

boto3-stubs provides comprehensive type annotations for the `boto3` AWS SDK for Python, enabling static type checking with tools like MyPy and PyRight, and enhancing IDE auto-completion. It is generated by `mypy-boto3-builder` and is actively maintained with frequent updates, typically aligning with `boto3` releases to ensure compatibility with the latest AWS services and features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `boto3-stubs` to add type annotations to `boto3` client calls. By installing `boto3-stubs` (or `boto3-stubs[s3]` for S3 specific stubs), type checkers like MyPy will understand the return types and argument types of `boto3.client('s3')`, and IDEs will provide better auto-completion. Explicitly importing `S3Client` from `mypy_boto3_s3.client` allows for clear type hinting of the client object itself.

import boto3
from mypy_boto3_s3.client import S3Client
import os

def list_s3_buckets(region_name: str = os.environ.get('AWS_REGION', 'us-east-1')) -> list[str]:
    """Lists S3 bucket names with type hints."""
    # boto3-stubs automatically provides type hints for client() and resource() calls
    s3_client: S3Client = boto3.client("s3", region_name=region_name)
    response = s3_client.list_buckets()
    bucket_names = [bucket['Name'] for bucket in response.get('Buckets', [])]
    return bucket_names

if __name__ == "__main__":
    print(f"S3 Buckets: {list_s3_buckets()}")

view raw JSON →