mypy-boto3 (Legacy Boto3 Type Stubs)
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
- breaking The `mypy-boto3` package is officially deprecated and no longer actively maintained. Users are strongly advised to migrate to `types-boto3` and its service-specific sub-packages for current features, bug fixes, and active support.
- gotcha Unlike `mypy-boto3`, which provided all service stubs in a single package, `types-boto3` promotes a modular approach with separate packages for each AWS service (e.g., `types-boto3-s3`, `types-boto3-lambda`). This reduces dependency footprint and improves type checking performance but requires installing each service individually or using the `[all]` extra.
- gotcha While `mypy-boto3` version 1.x.x itself requires Python `3.9` or newer, the successor `types-boto3` versions (8.12.0+) have explicitly dropped support for Python 3.8. Ensure your development and deployment environments are running Python 3.9 or newer to be compatible with `types-boto3`.
Install
-
pip install mypy-boto3 boto3 -
pip install 'types-boto3[all]' boto3 -
pip install 'types-boto3[s3,lambda]' boto3
Imports
- boto3.client
import boto3 s3_client = boto3.client('s3')
Quickstart
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}")