Type Annotations for boto3 CloudFormation
types-boto3-cloudformation provides type annotations for the `boto3` AWS SDK's CloudFormation service, compatible with static analysis tools like mypy, pyright, and IDEs such as VSCode and PyCharm. It is generated by the `mypy-boto3-builder` (currently version 8.12.0) and typically releases updates in sync with `boto3` to provide accurate type hints for the latest AWS service APIs. The current version of these annotations is 1.42.3, matching `boto3`'s version.
Warnings
- breaking Python 3.8 support was removed with `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 will need to upgrade to Python 3.9 or newer to use `types-boto3-cloudformation` versions generated by this builder version or newer.
- breaking Type definition (TypeDef) naming conventions changed in `mypy-boto3-builder` 8.9.0. Specifically, packed method arguments use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- gotcha This package provides *only* type annotations. The actual `boto3` library must be installed separately for your code to run at runtime. `types-boto3-cloudformation` does not include or replace the `boto3` runtime.
- gotcha PyCharm users might experience slow performance or high CPU usage due to `Literal` overloads (issue PY-40997). The recommendation is to use `types-boto3-lite` versions or disable PyCharm's internal type checker and use `mypy` or `pyright` externally.
- gotcha With the migration to PEP 561 packages in `mypy-boto3-builder` 8.12.0, while core import paths should remain stable, there's a potential for tooling that relied on non-standard stub discovery mechanisms to require updates or configuration adjustments.
Install
-
pip install types-boto3-cloudformation -
pip install 'types-boto3[cloudformation]'
Imports
- CloudFormationClient
from types_boto3_cloudformation.client import CloudFormationClient
- CloudFormationServiceResource
from types_boto3_cloudformation.service_resource import CloudFormationServiceResource
- StackSummaryTypeDef
from types_boto3_cloudformation.type_defs import StackSummaryTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from types_boto3_cloudformation.client import CloudFormationClient
from types_boto3_cloudformation.type_defs import StackSummaryTypeDef
# Create a boto3 client. Types are typically auto-discovered by IDEs/type checkers
# if types-boto3-cloudformation is installed.
client: CloudFormationClient = boto3.client("cloudformation")
try:
# Example: List CloudFormation stacks
response = client.list_stacks(StackStatusFilter=[
'CREATE_COMPLETE', 'UPDATE_COMPLETE', 'ROLLBACK_COMPLETE'
])
print("CloudFormation Stacks:")
for stack_summary: StackSummaryTypeDef in response.get("StackSummaries", []):
print(f" - {stack_summary['StackName']} ({stack_summary['StackStatus']})")
except Exception as e:
print(f"Error listing stacks: {e}")
# In a real application, handle specific AWS exceptions like ClientError