{"id":2605,"library":"mypy-boto3-kms","title":"mypy-boto3-kms Type Stubs for AWS KMS","description":"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.","status":"active","version":"1.42.50","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","kms","mypy","type-hints","stubs","static-analysis"],"install":[{"cmd":"pip install boto3 mypy-boto3-kms","lang":"bash","label":"Install boto3 and KMS stubs"}],"dependencies":[{"reason":"These are type stubs for boto3's KMS client. boto3 itself is required for runtime functionality.","package":"boto3","optional":false}],"imports":[{"symbol":"KMSClient","correct":"from mypy_boto3_kms.client import KMSClient"},{"note":"Pre-8.9.0 builder versions might have used shorter or different TypeDef names. Always check the generated stub files if unsure.","wrong":"from mypy_boto3_kms.type_defs import CreateKeyRequestTypeDef","symbol":"CreateKeyRequestRequestTypeDef","correct":"from mypy_boto3_kms.type_defs import CreateKeyRequestRequestTypeDef"},{"symbol":"ListKeysResponseTypeDef","correct":"from mypy_boto3_kms.type_defs import ListKeysResponseTypeDef"}],"quickstart":{"code":"import boto3\nfrom mypy_boto3_kms.client import KMSClient\nfrom mypy_boto3_kms.type_defs import ListKeysResponseTypeDef, CreateKeyRequestRequestTypeDef\n\n# Initialize a KMS client, type-hinted for static analysis\nkms_client: KMSClient = boto3.client(\"kms\")\n\n# Example operation: List KMS keys\ntry:\n    # mypy will verify the return type matches ListKeysResponseTypeDef\n    response: ListKeysResponseTypeDef = kms_client.list_keys()\n    print(\"KMS Keys:\")\n    for key in response.get(\"Keys\", []):\n        print(f\"  Key ID: {key.get('KeyId')}, Key ARN: {key.get('KeyArn')}\")\nexcept Exception as e:\n    print(f\"Error listing keys: {e}\")\n\n# Example of using a TypeDef for a request payload (for type-checking)\ncreate_key_params: CreateKeyRequestRequestTypeDef = {\n    \"Description\": \"My Test Key\",\n    \"KeyUsage\": \"ENCRYPT_DECRYPT\",\n    \"KeySpec\": \"SYMMETRIC_DEFAULT\",\n    \"Tags\": [\n        {\"TagKey\": \"Project\", \"TagValue\": \"MyProject\"}\n    ]\n}\n# mypy would check 'create_key_params' against 'CreateKeyRequestRequestTypeDef'\nprint(f\"\\nExample CreateKeyRequest parameters (for type-checking): {create_key_params}\")\n\n# To run mypy against this file:\n# mypy your_script_name.py\n","lang":"python","description":"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`."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or later.","message":"As of `mypy-boto3-builder` version 8.12.0, Python 3.8 support has been removed across all generated `mypy-boto3` packages. You must use Python 3.9 or newer.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.12.0, mypy-boto3-kms >=1.42.x"},{"fix":"Consult the `mypy-boto3-builder` changelog and update TypeDef names in your code. Auto-completion in IDEs usually helps find the correct new names.","message":"TypeDef naming conventions were significantly changed in `mypy-boto3-builder` 8.9.0. TypeDefs for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting 'Extra' postfixes moved to the end. Code relying on specific TypeDef names may break.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.9.0, mypy-boto3-kms >=1.40.x"},{"fix":"Ensure `pip install boto3` is part of your project's dependencies and that your AWS credentials are set up correctly.","message":"`mypy-boto3-kms` provides only type stubs. For your application to run, `boto3` must be installed and properly configured (e.g., AWS credentials) in your environment. These stubs do not provide any runtime functionality.","severity":"gotcha","affected_versions":"all"},{"fix":"Periodically update both `boto3` and `mypy-boto3-kms` to their latest compatible versions. The `mypy-boto3` project generally keeps stub versions in sync with the `boto3` service definition versions.","message":"The version of `mypy-boto3-kms` should ideally align with the `boto3` version you are using or the `boto3` service definition it was generated against. Mismatches can lead to incorrect type hints for newer or older API features.","severity":"gotcha","affected_versions":"all"},{"fix":"Review your `mypy` configuration (`mypy.ini`, `pyproject.toml`) and ensure it adheres to standard PEP 561 package discovery mechanisms. For most users, this change is transparent.","message":"The `mypy-boto3` packages migrated to PEP 561 compatible package structure in `mypy-boto3-builder` 8.12.0. If you have custom `mypy` configurations that rely on specific internal paths or non-PEP 561 layouts, you may need to update them.","severity":"gotcha","affected_versions":"mypy-boto3-builder >=8.12.0, mypy-boto3-kms >=1.42.x"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}