Skip to content

Examples#

Index > KMS > Examples

Auto-generated documentation for KMS type annotations stubs module types-aiobotocore-kms.

Client#

Implicit type annotations#

Can be used with types-aioboto3[kms] package installed.

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

# KMSClient usage example

from aioboto3.session import Session


session = Session()

async with session.client("kms") as client:  # (1)
    result = await client.cancel_key_deletion()  # (2)
  1. client: KMSClient
  2. result: CancelKeyDeletionResponseTypeDef
# DescribeCustomKeyStoresPaginator usage example

from aioboto3.session import Session


session = Session()

async with session.client("kms") as client:  # (1)
    paginator = client.get_paginator("describe_custom_key_stores")  # (2)
    async for item in paginator.paginate(...):
        print(item)  # (3)
  1. client: KMSClient
  2. paginator: DescribeCustomKeyStoresPaginator
  3. item: DescribeCustomKeyStoresResponseTypeDef

Explicit type annotations#

With types-aioboto3-lite[kms] or a standalone types_aiobotocore_kms package, you have to explicitly specify client: KMSClient 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.

# KMSClient usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_kms.client import KMSClient
from types_aiobotocore_kms.type_defs import CancelKeyDeletionResponseTypeDef
from types_aiobotocore_kms.type_defs import CancelKeyDeletionRequestRequestTypeDef


session = Session()

client: KMSClient
async with session.client("kms") as client:  # (1)
    kwargs: CancelKeyDeletionRequestRequestTypeDef = {...}  # (2)
    result: CancelKeyDeletionResponseTypeDef = await client.cancel_key_deletion(**kwargs)  # (3)
  1. client: KMSClient
  2. kwargs: CancelKeyDeletionRequestRequestTypeDef
  3. result: CancelKeyDeletionResponseTypeDef
# DescribeCustomKeyStoresPaginator usage example with type annotations

from aioboto3.session import Session

from types_aiobotocore_kms.client import KMSClient
from types_aiobotocore_kms.paginator import DescribeCustomKeyStoresPaginator
from types_aiobotocore_kms.type_defs import DescribeCustomKeyStoresResponseTypeDef


session = Session()

client: KMSClient
async with session.client("kms") as client:  # (1)
    paginator: DescribeCustomKeyStoresPaginator = client.get_paginator("describe_custom_key_stores")  # (2)
    async for item in paginator.paginate(...):
        item: DescribeCustomKeyStoresResponseTypeDef
        print(item)  # (3)
  1. client: KMSClient
  2. paginator: DescribeCustomKeyStoresPaginator
  3. item: DescribeCustomKeyStoresResponseTypeDef