mypy-boto3-cloudcontrol: Type Annotations for AWS Cloud Control API
mypy-boto3-cloudcontrol provides type annotations for the AWS boto3 CloudControlApi service. It is part of the larger `mypy-boto3-builder` ecosystem, which generates stubs for all boto3 services. This specific package, currently at version 1.42.3, helps static type checkers like Mypy understand the dynamic nature of boto3 clients, offering improved code completion, error detection, and overall developer experience for Cloud Control API interactions. The builder project releases frequently, often synchronizing with `boto3` and `botocore` updates.
Warnings
- breaking Python 3.8 support was removed starting with `mypy-boto3-builder` version 8.12.0 (and thus for generated packages like `mypy-boto3-cloudcontrol`). Projects using Python 3.8 will need to upgrade to Python 3.9 or newer.
- breaking The builder migrated to PEP 561 compatible packages in version 8.12.0. While this is generally an improvement for type checker discovery, it's a significant packaging change that might affect build systems or older `mypy` versions.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. Specifically, redundant 'Request' suffixes were removed (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting 'Extra' postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`).
- gotcha `mypy-boto3-cloudcontrol` provides only type annotations; it is not a runtime dependency. You must still install and use the `boto3` library for actual AWS interactions. Importing `mypy-boto3` types directly without `if TYPE_CHECKING:` can make it an unnecessary runtime dependency.
Install
-
pip install mypy-boto3-cloudcontrol boto3 mypy
Imports
- CloudControlClient
from mypy_boto3_cloudcontrol.client import CloudControlClient
- ResourceDescriptionTypeDef
from mypy_boto3_cloudcontrol.type_defs import ResourceDescriptionTypeDef
Quickstart
from typing import TYPE_CHECKING
import boto3
import os
# Only import type stubs when type checking
if TYPE_CHECKING:
from mypy_boto3_cloudcontrol.client import CloudControlClient
from mypy_boto3_cloudcontrol.type_defs import ListResourcesOutputTypeDef
def list_cloud_control_resources(client: 'CloudControlClient') -> 'ListResourcesOutputTypeDef':
"""Lists resources managed by AWS Cloud Control API."""
# Example: List up to 10 resources of a specific type
# Replace 'AWS::S3::Bucket' with an actual resource type if needed
response = client.list_resources(
TypeName='AWS::S3::Bucket', # Use a valid AWS resource type
MaxResults=10
)
print(f"Found {len(response.get('ResourceDescriptions', []))} resources.")
for resource in response.get('ResourceDescriptions', []):
print(f" - ID: {resource.get('Identifier')}, Name: {resource.get('ResourceModel')}")
return response
if __name__ == "__main__":
# Ensure AWS credentials are configured (e.g., via environment variables or AWS CLI)
# This is a runtime client, not directly from mypy-boto3-cloudcontrol
session = boto3.Session(
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
aws_session_token=os.environ.get('AWS_SESSION_TOKEN', ''),
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
cloudcontrol_client: 'CloudControlClient' = session.client("cloudcontrol")
try:
list_cloud_control_resources(cloudcontrol_client)
except Exception as e:
print(f"An error occurred: {e}")
print("Make sure 'AWS::S3::Bucket' (or chosen TypeName) is a valid and accessible resource type.")
# To run mypy:
# mypy your_script_name.py