Type annotations for boto3

1.42.85 · active · verified Thu Apr 09

types-boto3 provides comprehensive type annotations (stubs) for the boto3 library, enabling static type checkers like MyPy to validate usage of AWS services. It is generated by the mypy-boto3-builder project and is currently at version 1.42.85. New versions are released frequently, typically mirroring boto3 updates or adding builder improvements.

Warnings

Install

Imports

Quickstart

This example demonstrates how to type-hint a boto3 S3 client using `types-boto3-s3` stubs. The `TYPE_CHECKING` block ensures that stub imports are only processed by type checkers and don't introduce runtime dependencies.

import boto3
from typing import TYPE_CHECKING

# It's good practice to guard stub imports for runtime environments
if TYPE_CHECKING:
    from types_boto3_s3.client import S3Client
    from types_boto3_s3.type_defs import BucketTypeDef


def list_s3_buckets(client: "S3Client") -> list["BucketTypeDef"]:
    response = client.list_buckets()
    return response.get("Buckets", [])


if __name__ == "__main__":
    # In a real application, you'd configure credentials/region
    # via environment variables or ~/.aws/credentials
    s3_client: S3Client = boto3.client("s3")
    buckets = list_s3_buckets(s3_client)
    print(f"Found {len(buckets)} S3 buckets.")
    for bucket in buckets:
        print(f"- {bucket['Name']}")

view raw JSON →