mypy-boto3-cloudhsm Type Annotations for AWS CloudHSM

1.42.3 · active · verified Sat Apr 11

mypy-boto3-cloudhsm provides type annotations for the AWS CloudHSM service, designed to be used with `boto3`. It enhances development experience by enabling static type checking with tools like MyPy, Pylance, and IDEs like VSCode and PyCharm. The package is part of the `mypy-boto3-builder` ecosystem, which generates stubs for all `boto3` services, often releasing updates aligned with `boto3` and botocore releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-cloudhsm` for type hinting with a `boto3` CloudHSM client. The `TYPE_CHECKING` block ensures that type-hint-specific imports and assignments are only evaluated by type checkers and not at runtime, avoiding unnecessary dependencies in production. Remember to install `boto3` alongside `mypy-boto3-cloudhsm`.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_cloudhsm import CloudHSMClient
    from mypy_boto3_cloudhsm.type_defs import ListHsmsResponseTypeDef

# Initialize a boto3 client (runtime code)
client = boto3.client("cloudhsm")

# Type hint the client for static analysis
if TYPE_CHECKING:
    typed_client: CloudHSMClient = client
    response: ListHsmsResponseTypeDef = typed_client.list_hsms()

# Example of using the client (runtime code)
# For a real application, consider error handling and pagination
list_hsms_response = client.list_hsms()
print(f"CloudHSM HSMs: {list_hsms_response.get('Hsms', [])}")

view raw JSON →