mypy-boto3-kms Type Stubs for AWS KMS

1.42.50 · active · verified Fri Apr 10

mypy-boto3-kms provides static type annotations for the AWS Key Management Service (KMS) client in `boto3`, enhancing type safety and developer experience with tools like MyPy. It is part of the `mypy-boto3` collection, automatically generated by `mypy-boto3-builder`, and its current version (1.42.50) is synchronized with the underlying `boto3` service definition versions. The project maintains a regular release cadence, often updating with new `boto3` versions and `mypy-boto3-builder` enhancements.

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the KMSClient type for `boto3` client type-hinting, and how to use generated TypeDefs for request/response payloads to leverage static analysis with MyPy. Remember to install `boto3` alongside `mypy-boto3-kms`.

import boto3
from mypy_boto3_kms.client import KMSClient
from mypy_boto3_kms.type_defs import ListKeysResponseTypeDef, CreateKeyRequestRequestTypeDef

# Initialize a KMS client, type-hinted for static analysis
kms_client: KMSClient = boto3.client("kms")

# Example operation: List KMS keys
try:
    # mypy will verify the return type matches ListKeysResponseTypeDef
    response: ListKeysResponseTypeDef = kms_client.list_keys()
    print("KMS Keys:")
    for key in response.get("Keys", []):
        print(f"  Key ID: {key.get('KeyId')}, Key ARN: {key.get('KeyArn')}")
except Exception as e:
    print(f"Error listing keys: {e}")

# Example of using a TypeDef for a request payload (for type-checking)
create_key_params: CreateKeyRequestRequestTypeDef = {
    "Description": "My Test Key",
    "KeyUsage": "ENCRYPT_DECRYPT",
    "KeySpec": "SYMMETRIC_DEFAULT",
    "Tags": [
        {"TagKey": "Project", "TagValue": "MyProject"}
    ]
}
# mypy would check 'create_key_params' against 'CreateKeyRequestRequestTypeDef'
print(f"\nExample CreateKeyRequest parameters (for type-checking): {create_key_params}")

# To run mypy against this file:
# mypy your_script_name.py

view raw JSON →