Skip to content

Examples#

Index > CloudWatchLogs > Examples

Auto-generated documentation for CloudWatchLogs type annotations stubs module mypy-boto3-logs.

Client#

Implicit type annotations#

Can be used with boto3-stubs[logs] package installed.

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

# CloudWatchLogsClient usage example

from boto3.session import Session


session = Session()

client = session.client("logs")  # (1)
result = client.associate_kms_key()  # (2)
  1. client: CloudWatchLogsClient
  2. result: EmptyResponseMetadataTypeDef
# DescribeDestinationsPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("logs")  # (1)

paginator = client.get_paginator("describe_destinations")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: CloudWatchLogsClient
  2. paginator: DescribeDestinationsPaginator
  3. item: DescribeDestinationsResponseTypeDef

Explicit type annotations#

With boto3-stubs-lite[logs] or a standalone mypy_boto3_logs package, you have to explicitly specify client: CloudWatchLogsClient 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.

# CloudWatchLogsClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_logs.client import CloudWatchLogsClient
from mypy_boto3_logs.type_defs import EmptyResponseMetadataTypeDef
from mypy_boto3_logs.type_defs import AssociateKmsKeyRequestRequestTypeDef


session = Session()

client: CloudWatchLogsClient = session.client("logs")

kwargs: AssociateKmsKeyRequestRequestTypeDef = {...}
result: EmptyResponseMetadataTypeDef = client.associate_kms_key(**kwargs)
# DescribeDestinationsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_logs.client import CloudWatchLogsClient
from mypy_boto3_logs.paginator import DescribeDestinationsPaginator
from mypy_boto3_logs.type_defs import DescribeDestinationsResponseTypeDef


session = Session()
client: CloudWatchLogsClient = session.client("logs")

paginator: DescribeDestinationsPaginator = client.get_paginator("describe_destinations")
for item in paginator.paginate(...):
    item: DescribeDestinationsResponseTypeDef
    print(item)