mypy-boto3-cost-optimization-hub Type Annotations

1.42.3 · active · verified Sat Apr 11

This library provides comprehensive type annotations for the `boto3` AWS SDK's Cost Optimization Hub service. Generated by `mypy-boto3-builder`, it ensures full type checking compatibility with tools like MyPy, Pyright, VSCode, and PyCharm, enabling developers to write more robust and error-free AWS-interacting Python code. The current version is 1.42.3, following the active and frequent release cadence of the underlying `mypy-boto3-builder` project.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a type-hinted `CostOptimizationHubClient` and perform a basic API call, `list_recommendation_summaries`. It includes the recommended `TYPE_CHECKING` guard for stub imports and basic error handling.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_cost_optimization_hub.client import CostOptimizationHubClient
    from mypy_boto3_cost_optimization_hub.type_defs import ListRecommendationSummariesResponseTypeDef

def get_cost_optimization_client() -> CostOptimizationHubClient:
    """Returns a type-hinted CostOptimizationHub client."""
    session = boto3.session.Session()
    return session.client("cost-optimization-hub")

client: CostOptimizationHubClient = get_cost_optimization_client()

try:
    # Example: List recommendation summaries
    response: ListRecommendationSummariesResponseTypeDef = client.list_recommendation_summaries()
    print(f"Recommendations found: {len(response.get('RecommendationSummaries', []))}")
    for summary in response.get('RecommendationSummaries', []):
        print(f"  - {summary.get('RecommendationTarget')}: {summary.get('EstimatedSavings', {}).get('Amount')}")
except client.exceptions.AccessDeniedException as e:
    print(f"Error: Access Denied. Ensure you have permissions for Cost Optimization Hub. Details: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →