mypy-boto3 (Legacy Boto3 Type Stubs)

1.42.3 · deprecated · verified Sun Apr 12

This package provides legacy type annotations for the `boto3` AWS SDK. As of version `1.42.3`, it is officially deprecated in favor of `types-boto3`. It enhances `boto3` code with static type checking capabilities (e.g., with MyPy) by providing a single package with stubs for all AWS services. The recommended successor, `types-boto3`, offers more granular, service-specific stub packages and is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how `mypy-boto3` (or its successor `types-boto3`) enhances standard `boto3` usage with type annotations. Installing the stubs allows static analysis tools like MyPy and IDEs to provide accurate type information, autocomplete, and error checking for `boto3` client methods and their responses.

import boto3
from typing import Optional

def get_s3_bucket_location(bucket_name: str) -> Optional[str]:
    s3_client = boto3.client('s3')
    # The response type from get_bucket_location will be fully type-hinted
    response = s3_client.get_bucket_location(Bucket=bucket_name)
    location = response.get('LocationConstraint')
    return location

# Example usage (requires AWS credentials configured and bucket to exist)
# try:
#     # For a bucket like 'your-unique-test-bucket-123'
#     location = get_s3_bucket_location('your-unique-test-bucket-123')
#     if location is not None:
#         print(f"Bucket location: {location}")
#     else:
#         print("Bucket location is 'us-east-1' (default) or not set.")
# except Exception as e:
#     print(f"Error fetching bucket location: {e}")

view raw JSON →