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
# DescribeConfigurationTemplatesPaginator usage example

from boto3.session import Session


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

paginator = client.get_paginator("describe_configuration_templates")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: CloudWatchLogsClient
  2. paginator: DescribeConfigurationTemplatesPaginator
  3. item: DescribeConfigurationTemplatesResponseTypeDef

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)
# DescribeConfigurationTemplatesPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_logs.client import CloudWatchLogsClient
from mypy_boto3_logs.paginator import DescribeConfigurationTemplatesPaginator
from mypy_boto3_logs.type_defs import DescribeConfigurationTemplatesResponseTypeDef


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

paginator: DescribeConfigurationTemplatesPaginator = client.get_paginator("describe_configuration_templates")
for item in paginator.paginate(...):
    item: DescribeConfigurationTemplatesResponseTypeDef
    print(item)