Skip to content

Examples#

Index > CloudHSM > Examples

Auto-generated documentation for CloudHSM type annotations stubs module mypy-boto3-cloudhsm.

Client#

Implicit type annotations#

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

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

# CloudHSMClient usage example

from boto3.session import Session


session = Session()

client = session.client("cloudhsm")  # (1)
result = client.add_tags_to_resource()  # (2)
  1. client: CloudHSMClient
  2. result: AddTagsToResourceResponseTypeDef
# ListHapgsPaginator usage example

from boto3.session import Session


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

paginator = client.get_paginator("list_hapgs")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: CloudHSMClient
  2. paginator: ListHapgsPaginator
  3. item: ListHapgsResponseTypeDef

Explicit type annotations#

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

# CloudHSMClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_cloudhsm.client import CloudHSMClient
from mypy_boto3_cloudhsm.type_defs import AddTagsToResourceResponseTypeDef
from mypy_boto3_cloudhsm.type_defs import AddTagsToResourceRequestRequestTypeDef


session = Session()

client: CloudHSMClient = session.client("cloudhsm")

kwargs: AddTagsToResourceRequestRequestTypeDef = {...}
result: AddTagsToResourceResponseTypeDef = client.add_tags_to_resource(**kwargs)
# ListHapgsPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_cloudhsm.client import CloudHSMClient
from mypy_boto3_cloudhsm.paginator import ListHapgsPaginator
from mypy_boto3_cloudhsm.type_defs import ListHapgsResponseTypeDef


session = Session()
client: CloudHSMClient = session.client("cloudhsm")

paginator: ListHapgsPaginator = client.get_paginator("list_hapgs")
for item in paginator.paginate(...):
    item: ListHapgsResponseTypeDef
    print(item)