Skip to content

Examples#

Index > CloudWatch > Examples

Auto-generated documentation for CloudWatch type annotations stubs module types-aiobotocore-cloudwatch.

Client#

Implicit type annotations#

Can be used with types-aiobotocore[cloudwatch] package installed.

Write your CloudWatch code as usual, type checking and code completion should work out of the box.

# CloudWatchClient usage example

from aiobotocore.session import get_session


session = get_session()

async with session.create_client("cloudwatch") as client:  # (1)
    result = await client.delete_alarms()  # (2)
  1. client: CloudWatchClient
  2. result: EmptyResponseMetadataTypeDef
# DescribeAlarmHistoryPaginator usage example

from aiobotocore.session import get_session


session = get_session()

async with session.create_client("cloudwatch") as client:  # (1)
    paginator = client.get_paginator("describe_alarm_history")  # (2)
    async for item in paginator.paginate(...):
        print(item)  # (3)
  1. client: CloudWatchClient
  2. paginator: DescribeAlarmHistoryPaginator
  3. item: DescribeAlarmHistoryOutputTypeDef
# AlarmExistsWaiter usage example

from aiobotocore.session import get_session


session = get_session()

async with session.create_client("cloudwatch") as client:  # (1)
    waiter = client.get_waiter("alarm_exists")  # (2)
    await waiter.wait()
  1. client: CloudWatchClient
  2. waiter: AlarmExistsWaiter

Explicit type annotations#

With types-aiobotocore-lite[cloudwatch] or a standalone types_aiobotocore_cloudwatch package, you have to explicitly specify client: CloudWatchClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

# CloudWatchClient usage example with type annotations

from aiobotocore.session import get_session

from types_aiobotocore_cloudwatch.client import CloudWatchClient
from types_aiobotocore_cloudwatch.type_defs import EmptyResponseMetadataTypeDef
from types_aiobotocore_cloudwatch.type_defs import DeleteAlarmsInputRequestTypeDef


session = get_session()

async with session.create_client("cloudwatch") as client:
    client: CloudWatchClient
    kwargs: DeleteAlarmsInputRequestTypeDef = {...}
    result: EmptyResponseMetadataTypeDef = await client.delete_alarms(**kwargs)
# DescribeAlarmHistoryPaginator usage example with type annotations

from aiobotocore.session import get_session

from types_aiobotocore_cloudwatch.client import CloudWatchClient
from types_aiobotocore_cloudwatch.paginator import DescribeAlarmHistoryPaginator
from types_aiobotocore_cloudwatch.type_defs import DescribeAlarmHistoryOutputTypeDef


session = get_session()

async with session.create_client("cloudwatch") as client:
    client: CloudWatchClient
    paginator: DescribeAlarmHistoryPaginator = client.get_paginator("describe_alarm_history")
    async for item in paginator.paginate(...):
        item: DescribeAlarmHistoryOutputTypeDef
        print(item)
# AlarmExistsWaiter usage example with type annotations

from aiobotocore.session import get_session

from types_aiobotocore_cloudwatch.client import CloudWatchClient
from types_aiobotocore_cloudwatch.waiter import AlarmExistsWaiter


session = get_session()

async with session.create_client("cloudwatch") as client:
    client: CloudWatchClient
    waiter: AlarmExistsWaiter = client.get_waiter("alarm_exists")
    await waiter.wait()