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

from boto3.session import Session


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

paginator = client.get_paginator("describe_deliveries")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: CloudWatchLogsClient
  2. paginator: DescribeDeliveriesPaginator
  3. item: DescribeDeliveriesResponseTypeDef

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

from boto3.session import Session

from mypy_boto3_logs.client import CloudWatchLogsClient
from mypy_boto3_logs.paginator import DescribeDeliveriesPaginator
from mypy_boto3_logs.type_defs import DescribeDeliveriesResponseTypeDef


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

paginator: DescribeDeliveriesPaginator = client.get_paginator("describe_deliveries")
for item in paginator.paginate(...):
    item: DescribeDeliveriesResponseTypeDef
    print(item)