mypy-boto3-cost-optimization-hub Type Annotations
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
- breaking Python 3.8 support was removed starting with `mypy-boto3-builder` version 8.12.0. Consequently, `mypy-boto3-cost-optimization-hub` version 1.42.3 and newer require Python 3.9 or higher.
- breaking The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages with `mypy-boto3-builder` version 8.12.0. While this improves packaging standards, it might affect custom build processes or older environments directly consuming `mypy-boto3-builder` outputs, though direct `pip install` users should see minimal impact.
- gotcha To avoid runtime dependencies on `mypy-boto3-cost-optimization-hub` and prevent potential Pylint warnings, always wrap type-specific imports (e.g., `CostOptimizationHubClient`, `TypeDefs`) within an `if TYPE_CHECKING:` block.
- breaking Across the `mypy-boto3` family, `TypeDef` naming conventions changed with `mypy-boto3-builder` version 8.9.0. This involved shortening packed method argument TypeDefs (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`) and moving 'Extra' postfixes.
Install
-
pip install mypy-boto3-cost-optimization-hub -
pip install 'boto3-stubs[cost-optimization-hub]'
Imports
- CostOptimizationHubClient
from typing import TYPE_CHECKING if TYPE_CHECKING: from mypy_boto3_cost_optimization_hub.client import CostOptimizationHubClient - ResponseMetadataTypeDef
from typing import TYPE_CHECKING if TYPE_CHECKING: from mypy_boto3_cost_optimization_hub.type_defs import ResponseMetadataTypeDef
Quickstart
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}")