Type Annotations for boto3 CloudFront

1.42.80 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This example demonstrates how to initialize a `boto3` CloudFront client with type hints and retrieve a list of distributions. It uses `TYPE_CHECKING` for conditional imports, ensuring the stub package is only a development dependency. The response items are type-hinted using a `DistributionSummaryTypeDef`.

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}")

view raw JSON →