Type Annotations for boto3 CloudFront
mypy-boto3-cloudfront provides type annotations for the AWS boto3 CloudFront service. It enhances development experience with static type checking, auto-completion, and early error detection in IDEs and with tools like mypy. This package, version 1.42.80, is generated with `mypy-boto3-builder 8.12.0` and receives frequent updates in sync with `boto3` releases.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-cloudfront 1.42.80`), support for Python 3.8 has been removed. Projects using this version of the stubs or newer require Python 3.9 or higher.
- breaking Builder version 8.9.0 introduced breaking changes to TypeDef naming conventions. For instance, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`, and `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`. If you're explicitly using these full TypeDef names, they may need to be updated.
- gotcha The version of `mypy-boto3-cloudfront` typically aligns with the `boto3` version it provides stubs for (e.g., `1.42.80` for `boto3==1.42.80`). Using significantly mismatched `boto3` and `mypy-boto3-*` versions can lead to type checking errors or missing type hints if API signatures have changed between versions.
- gotcha When using explicit type annotations, some IDEs (like VSCode without full function overload support) may require explicitly importing `Client` types and `TypeDef` structures. While `mypy` and PyCharm might infer types more readily, explicit imports ensure consistent behavior across tools.
Install
-
pip install mypy-boto3-cloudfront -
pip install boto3 'mypy-boto3-cloudfront'
Imports
- CloudFrontClient
from mypy_boto3_cloudfront.client import CloudFrontClient
- DistributionTypeDef
from mypy_boto3_cloudfront.type_defs import DistributionSummaryTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_cloudfront.client import CloudFrontClient
from mypy_boto3_cloudfront.type_defs import DistributionSummaryTypeDef
# Instantiate a boto3 client (type-hinted for mypy)
cloudfront_client: 'CloudFrontClient' = boto3.client('cloudfront')
# Example: List distributions with type-hinted response
try:
response = cloudfront_client.list_distributions()
distributions: list['DistributionSummaryTypeDef'] = response.get('DistributionList', {}).get('Items', [])
if distributions:
print(f"Found {len(distributions)} CloudFront distributions.")
for dist in distributions:
print(f" Distribution ID: {dist.get('Id')}, Domain Name: {dist.get('DomainName')}")
else:
print("No CloudFront distributions found.")
except Exception as e:
print(f"Error listing distributions: {e}")