mypy-boto3-compute-optimizer
mypy-boto3-compute-optimizer provides type annotations for the boto3 AWS SDK, specifically for the Compute Optimizer service. It ensures static type checking for your boto3 calls related to Compute Optimizer, improving code reliability and developer experience. The current version is 1.42.3, and it's part of the frequently updated mypy-boto3-builder ecosystem, with new versions often released alongside boto3 updates or builder improvements.
Warnings
- breaking Support for Python 3.8 has been removed in mypy-boto3-builder version 8.12.0 and subsequent stub packages. Your project must use Python 3.9 or newer.
- breaking TypeDef naming conventions changed in mypy-boto3-builder 8.9.0. This might affect explicit imports of TypeDefs (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`).
- gotcha This package provides type stubs only. You must also install the `boto3` library for your code to run at runtime. Without `boto3`, your application will fail with import errors.
- gotcha This is a service-specific stub package for AWS Compute Optimizer. If you need type annotations for other AWS services (e.g., S3, EC2), you must install their respective `mypy-boto3-<service-name>` packages.
Install
-
pip install mypy-boto3-compute-optimizer boto3
Imports
- ComputeOptimizerClient
from mypy_boto3_compute_optimizer import ComputeOptimizerClient
- DescribeRecommendationSummariesResponseTypeDef
from mypy_boto3_compute_optimizer.type_defs import DescribeRecommendationSummariesResponseTypeDef
- Client
import boto3 from mypy_boto3_compute_optimizer import Client as ComputeOptimizerClientType
Quickstart
import boto3
from mypy_boto3_compute_optimizer import ComputeOptimizerClient
from mypy_boto3_compute_optimizer.type_defs import ListRecommendationSummariesResponseTypeDef
# Ensure boto3 is installed: pip install boto3 mypy-boto3-compute-optimizer
def get_compute_optimizer_summary():
# The type hint 'ComputeOptimizerClient' provides static analysis for client methods.
client: ComputeOptimizerClient = boto3.client("compute-optimizer")
# The type hint 'ListRecommendationSummariesResponseTypeDef' helps with response structure.
response: ListRecommendationSummariesResponseTypeDef = client.list_recommendation_summaries()
print("Account Recommendation Summaries:")
for summary in response.get("RecommendationSummaries", []):
print(f" Account ID: {summary.get('AccountId')}, ")
print(f" Recommendation Count: {summary.get('RecommendationCount')}")
if __name__ == "__main__":
get_compute_optimizer_summary()