mypy-boto3-cloudhsmv2
mypy-boto3-cloudhsmv2 provides type annotations (stubs) for the `boto3` AWS SDK, specifically for the CloudHSMV2 service. It enhances development experience by enabling static type checking for `boto3` clients and responses. The library is currently at version 1.42.3, with releases closely mirroring `boto3` service updates and more frequent updates for the underlying `mypy-boto3-builder`.
Warnings
- breaking Support for Python 3.8 was removed in version 8.12.0 of the `mypy-boto3-builder` and subsequently in generated packages like `mypy-boto3-cloudhsmv2`.
- breaking TypeDef naming conventions changed in version 8.9.0 (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). This can break code that explicitly imports or references these generated type definition names.
- gotcha This library provides *type stubs* for `boto3`, it does not include `boto3` itself. You must install `boto3` separately to actually run your code.
- gotcha For effective type checking, the version of `mypy-boto3-cloudhsmv2` should closely match the `boto3` version you are using. Mismatched versions can lead to incorrect type hints or missing attributes.
- gotcha To benefit from these type annotations, you need to use a static type checker like `mypy`. Simply installing the stubs will not magically add type checking to your runtime Python code.
Install
-
pip install mypy-boto3-cloudhsmv2 -
pip install boto3 mypy
Imports
- CloudHSMV2Client
from mypy_boto3_cloudhsmv2.client import CloudHSMV2Client
- DescribeClustersResponseTypeDef
from mypy_boto3_cloudhsmv2.type_defs import DescribeClustersResponseTypeDef
Quickstart
import boto3
from mypy_boto3_cloudhsmv2.client import CloudHSMV2Client
from mypy_boto3_cloudhsmv2.type_defs import DescribeClustersResponseTypeDef
import os # For example credentials
def get_cloudhsmv2_clusters() -> None:
# Ensure AWS credentials are configured (e.g., via environment variables, ~/.aws/credentials)
# For this example to run without errors, ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
# and AWS_REGION are set in your environment if not using IAM roles or config files.
# The type annotation helps type checkers understand the client's methods and return types.
client: CloudHSMV2Client = boto3.client("cloudhsmv2", region_name=os.environ.get('AWS_REGION', 'us-east-1'))
try:
response: DescribeClustersResponseTypeDef = client.describe_clusters()
print("Successfully described CloudHSM V2 clusters:")
for cluster in response.get('Clusters', []):
print(f" - Cluster ID: {cluster.get('ClusterId')}, State: {cluster.get('State')}")
except Exception as e:
print(f"Error describing clusters: {e}")
if __name__ == "__main__":
# This code requires valid AWS credentials to run successfully.
# For type checking, simply running `mypy your_script.py` is sufficient.
get_cloudhsmv2_clusters()