{"id":5530,"library":"types-aiobotocore-cloudwatch","title":"Type Annotations for aiobotocore CloudWatch","description":"This library provides comprehensive type annotations (stubs) for the `aiobotocore` CloudWatch service client. It enables static type checkers like MyPy to validate the usage of `aiobotocore.client.CloudWatch` methods, parameters, and return types, significantly enhancing code quality and reducing runtime errors. Generated by `mypy-boto3-builder`, it is updated frequently to align with the latest AWS API definitions and `aiobotocore` releases.","status":"active","version":"3.4.0","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","aiobotocore","cloudwatch","types","mypy","stubs"],"install":[{"cmd":"pip install types-aiobotocore-cloudwatch aiobotocore","lang":"bash","label":"Install with runtime dependency"}],"dependencies":[{"reason":"Runtime dependency for which these are type stubs. Required for actual execution.","package":"aiobotocore","optional":false}],"imports":[{"note":"Import the typed client from the stub package for explicit type hinting.","symbol":"CloudWatchClient","correct":"from types_aiobotocore_cloudwatch.client import CloudWatchClient"},{"note":"Import specific TypeDefs for precise type annotations of input/output dictionaries.","symbol":"PutMetricDataInputRequestTypeDef","correct":"from types_aiobotocore_cloudwatch.type_defs import PutMetricDataInputRequestTypeDef"}],"quickstart":{"code":"import asyncio\nimport os\nfrom aiobotocore.session import get_session\nfrom types_aiobotocore_cloudwatch.client import CloudWatchClient\nfrom types_aiobotocore_cloudwatch.type_defs import PutMetricDataInputRequestTypeDef\n\nasync def put_cloudwatch_metric():\n    session = get_session()\n    # Ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION are set as environment variables\n    async with session.create_client(\n        \"cloudwatch\",\n        aws_access_key_id=os.environ.get(\"AWS_ACCESS_KEY_ID\", \"\"),\n        aws_secret_access_key=os.environ.get(\"AWS_SECRET_ACCESS_KEY\", \"\"),\n        region_name=os.environ.get(\"AWS_REGION\", \"us-east-1\")\n    ) as client:\n        # client is automatically type-hinted as CloudWatchClient by static analysis\n        # For explicit hinting:\n        cloudwatch_client: CloudWatchClient = client\n\n        metric_data: PutMetricDataInputRequestTypeDef = {\n            \"Namespace\": \"MyApplication\",\n            \"MetricData\": [\n                {\n                    \"MetricName\": \"RequestCount\",\n                    \"Dimensions\": [\n                        {\"Name\": \"Environment\", \"Value\": \"Production\"},\n                    ],\n                    \"Value\": 1.0,\n                    \"Unit\": \"Count\",\n                },\n            ],\n        }\n\n        response = await cloudwatch_client.put_metric_data(\n            Namespace=metric_data[\"Namespace\"],\n            MetricData=metric_data[\"MetricData\"]\n        )\n        print(f\"PutMetricData response: {response}\")\n\nif __name__ == \"__main__\":\n    # Example usage: set dummy env vars if not truly interacting with AWS\n    os.environ.setdefault(\"AWS_ACCESS_KEY_ID\", \"DUMMY_KEY\")\n    os.environ.setdefault(\"AWS_SECRET_ACCESS_KEY\", \"DUMMY_SECRET\")\n    os.environ.setdefault(\"AWS_REGION\", \"us-east-1\")\n    asyncio.run(put_cloudwatch_metric())","lang":"python","description":"This quickstart demonstrates how to use `types-aiobotocore-cloudwatch` for type hinting an `aiobotocore` CloudWatch client. It creates a client, prepares metric data using a `TypeDef`, and calls `put_metric_data` with full type safety."},"warnings":[{"fix":"Ensure your project uses Python 3.9 or newer. Check your `pyproject.toml` or `requirements.txt` for `python_requires`.","message":"Starting with `mypy-boto3-builder` version 8.12.0 (which generated `types-aiobotocore-cloudwatch` 3.4.0), Python 3.8 is no longer supported for these type stubs. The package requires Python >= 3.9.","severity":"breaking","affected_versions":"types-aiobotocore-cloudwatch >= 3.4.0"},{"fix":"Update your import statements to explicitly import type symbols from `types_aiobotocore_cloudwatch` (e.g., `from types_aiobotocore_cloudwatch.client import CloudWatchClient`).","message":"As of `mypy-boto3-builder` version 8.12.0, all `types-aiobotocore` packages officially migrated to PEP 561 native namespace packages. While type checkers generally find stubs, for explicit and robust type hinting, it is recommended to directly import types (like `CloudWatchClient` or `TypeDefs`) from the `types_aiobotocore_cloudwatch` package rather than relying on inferred types from `aiobotocore`'s runtime imports.","severity":"gotcha","affected_versions":"types-aiobotocore-cloudwatch >= 3.4.0"},{"fix":"Consult the `types-aiobotocore-cloudwatch` documentation or source for the correct `TypeDef` names and adjust your code accordingly.","message":"`mypy-boto3-builder` version 8.9.0 introduced changes to `TypeDef` naming conventions. Some argument TypeDefs might have shorter names (e.g., `RequestRequestTypeDef` became `RequestTypeDef`), and `Extra` postfixes might have moved. While not every service is affected in the same way, verify your custom `TypeDef` usage if you encounter type-checking errors related to dictionary shapes.","severity":"breaking","affected_versions":"types-aiobotocore-cloudwatch >= 3.1.0 (generated by builder 8.9.0)"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}