mypy-boto3-cloudhsm Type Annotations for AWS CloudHSM
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
- breaking Python 3.8 support has been removed. All `mypy-boto3-*` packages, including `mypy-boto3-cloudhsm`, now require Python 3.9 or higher due to changes in `mypy-boto3-builder` version 8.12.0.
- breaking Packages generated by `mypy-boto3-builder` (version 8.12.0 and above) now follow PEP 561 for distributing type information. This change might affect how type checkers discover and apply stubs in certain environments or older project configurations.
- gotcha This library provides *only* type annotations for the AWS CloudHSM service. You must install the `boto3` library separately for actual runtime functionality and API calls. `mypy-boto3-cloudhsm` is not a standalone AWS SDK.
- gotcha For optimal type checking accuracy, it is recommended to keep the `mypy-boto3-cloudhsm` version aligned with the major and minor version of your `boto3` installation. The stubs are generated based on specific AWS API versions, and mismatches can lead to incomplete or incorrect type hints.
- breaking Breaking changes to TypeDef naming conventions (e.g., shorter names for packed method arguments, conflict resolution) were introduced in `mypy-boto3-builder` version 8.9.0. While described generally for 'services', these changes can affect any service's generated TypeDefs, including CloudHSM.
Install
-
pip install boto3 mypy-boto3-cloudhsm
Imports
- CloudHSMClient
from mypy_boto3_cloudhsm import CloudHSMClient
- ListHsmsResponseTypeDef
from mypy_boto3_cloudhsm.type_defs import ListHsmsResponseTypeDef
Quickstart
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', [])}")