{"id":2598,"library":"mypy-boto3-cloudwatch","title":"Type annotations for boto3 CloudWatch","description":"mypy-boto3-cloudwatch provides type annotations for the `boto3` CloudWatch service, generated by `mypy-boto3-builder`. It enhances development with static type checking, autocompletion, and bug detection for `boto3` CloudWatch clients. The library is actively maintained with frequent updates to align with new `boto3` versions.","status":"active","version":"1.42.82","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["typing","boto3","aws","cloudwatch","stubs","mypy","type-checking"],"install":[{"cmd":"pip install mypy-boto3-cloudwatch boto3","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Runtime dependency for AWS SDK functionality. mypy-boto3-cloudwatch only provides type stubs.","package":"boto3","optional":false}],"imports":[{"note":"Import the specific client type for detailed type hints.","symbol":"CloudWatchClient","correct":"from mypy_boto3_cloudwatch.client import CloudWatchClient"},{"note":"Import TypeDefs for precise type checking of request/response structures.","symbol":"PutMetricDataInputRequestTypeDef","correct":"from mypy_boto3_cloudwatch.type_defs import PutMetricDataInputRequestTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_cloudwatch.client import CloudWatchClient\nfrom mypy_boto3_cloudwatch.type_defs import PutMetricDataInputRequestTypeDef\n\n# Instantiate a CloudWatch client with type annotation\nclient: CloudWatchClient = boto3.client(\n    \"cloudwatch\",\n    region_name=\"us-east-1\",\n    aws_access_key_id=\"AKIATESTKEY\", # Use os.environ.get('AWS_ACCESS_KEY_ID', '') in real code\n    aws_secret_access_key=\"YOUR_SECRET_KEY\" # Use os.environ.get('AWS_SECRET_ACCESS_KEY', '') in real code\n)\n\n# Example of using a TypeDef for a request payload\nmetric_data: PutMetricDataInputRequestTypeDef = {\n    \"Namespace\": \"MyApplication\",\n    \"MetricData\": [\n        {\n            \"MetricName\": \"CustomMetric\",\n            \"Dimensions\": [\n                {\"Name\": \"Environment\", \"Value\": \"Production\"}\n            ],\n            \"Value\": 10.5,\n            \"Unit\": \"Count\",\n        }\n    ],\n}\n\ntry:\n    response = client.put_metric_data(**metric_data)\n    print(f\"Successfully put metric data: {response['ResponseMetadata']['HTTPStatusCode']}\")\nexcept Exception as e:\n    print(f\"Error putting metric data: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to instantiate a `boto3` CloudWatch client with explicit type hints from `mypy-boto3-cloudwatch` and how to use a generated TypeDef for a method's input parameters."},"warnings":[{"fix":"Upgrade your Python environment to 3.9+.","message":"Python 3.8 support has been removed since version 8.12.0 of `mypy-boto3-builder` (which generates this package). Ensure your project uses Python 3.9 or higher.","severity":"breaking","affected_versions":">=8.12.0"},{"fix":"Ensure you `pip install mypy-boto3-cloudwatch` directly. If you were using `boto3-stubs[cloudwatch]`, switch to the direct package.","message":"The `mypy-boto3` ecosystem has migrated to PEP 561-compatible packages since builder version 8.12.0. This means you should now directly install `mypy-boto3-cloudwatch` rather than relying on `boto3-stubs` for service-specific types.","severity":"breaking","affected_versions":">=8.12.0"},{"fix":"Review your TypeDef imports and usages, adjusting names according to the new conventions.","message":"Breaking changes in `mypy-boto3-builder` 8.9.0 introduced shorter TypeDef names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and moved `Extra` postfixes. If you directly imported and used these TypeDefs, your code may break.","severity":"breaking","affected_versions":">=8.9.0"},{"fix":"Ensure `boto3` is installed in your environment: `pip install boto3`.","message":"This package provides *only* type annotations. You must install `boto3` separately to have the runtime functionality for interacting with AWS services.","severity":"gotcha","affected_versions":"*"},{"fix":"Consider simplifying your type hinting where auto-discovery works, but explicit imports provide the most robust type checking.","message":"While explicit type annotations are often beneficial, recent `mypy-boto3` versions offer auto-discovery for `boto3.client` and `boto3.resource` calls. Your IDE (e.g., VSCode with Pylance, PyCharm with mypy plugin) should pick up types automatically without explicit imports of `CloudWatchClient` in many cases.","severity":"gotcha","affected_versions":">=8.7.0"},{"fix":"Wrap type-specific imports with `from typing import TYPE_CHECKING` and define runtime fallbacks: `if TYPE_CHECKING: from mypy_boto3_cloudwatch.client import CloudWatchClient else: CloudWatchClient = object`.","message":"For Pylint compatibility and to avoid runtime dependencies on `mypy-boto3-cloudwatch` in production, it is recommended to guard type imports with `if TYPE_CHECKING:` to set types to `object` at runtime.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}