boto3-stubs-full
boto3-stubs-full provides comprehensive type annotations (stubs) for the dynamically typed boto3 library, enhancing static analysis, IDE autocompletion, and early error detection for AWS Python development. It is generated by `mypy-boto3-builder` and currently supports boto3 version 1.42.88. The project maintains an active release cadence, typically aligning with boto3 updates.
Warnings
- breaking Python 3.8 support has been removed. Projects using Python 3.8 must either upgrade Python or pin `boto3-stubs-full` to a version prior to 8.12.0.
- breaking The `sms-voice` service is no longer supported and has been removed. Use `pinpoint-sms-voice` instead.
- breaking Breaking changes were introduced to `TypeDef` naming conventions. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`, and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`).
- gotcha Mismatched versions between `boto3` and `boto3-stubs-full` can lead to incorrect or missing type hints. The `boto3-stubs` project generally aims to keep pace with `boto3` releases.
- gotcha PyCharm users may experience slow performance or high CPU usage due to `Literal` overloads. It is recommended to use `boto3-stubs-lite` or an external type checker (like MyPy or Pyright) with PyCharm's type checker disabled.
- gotcha When importing specific `mypy_boto3_*` types (e.g., `from mypy_boto3_s3.client import S3Client`), it is best practice to wrap these imports within an `if TYPE_CHECKING:` block. Failing to do so can make the stubs an unnecessary runtime dependency, potentially leading to circular import issues or larger deployment sizes.
Install
-
pip install boto3 boto3-stubs-full
Imports
- boto3
import boto3
- S3Client
from typing import TYPE_CHECKING if TYPE_CHECKING: from mypy_boto3_s3.client import S3Client
Quickstart
from typing import TYPE_CHECKING
import boto3
import os
# Boto3-stubs-full enhances type checking for standard boto3 usage.
# For explicit type annotations, import service clients within a TYPE_CHECKING block.
if TYPE_CHECKING:
from mypy_boto3_s3.client import S3Client
def list_s3_buckets(region: str) -> None:
# Initialize an S3 client. IDEs and type checkers will recognize the type
# even without explicit type hints if boto3-stubs-full is installed.
s3_client: S3Client = boto3.client('s3', region_name=region)
print(f"Listing S3 buckets in {region}:")
try:
response = s3_client.list_buckets()
for bucket in response.get('Buckets', []):
print(f"- {bucket['Name']}")
except Exception as e:
print(f"Error listing buckets: {e}")
if __name__ == "__main__":
aws_region = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
list_s3_buckets(aws_region)