{"id":8738,"library":"types-boto3-kms","title":"Type annotations for boto3 KMS","description":"types-boto3-kms provides static type annotations for the `boto3` AWS SDK's Key Management Service (KMS) client, compatible with static analysis tools like Mypy, Pyright, and IDEs such as VSCode and PyCharm. It enhances `boto3` code with autocompletion, type checking, and early error detection for KMS operations. This package is part of the `mypy-boto3-builder` ecosystem, currently at version 1.42.50, and releases are frequently updated to match `boto3` versions.","status":"active","version":"1.42.50","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","boto3","type-hints","mypy","kms","static-analysis"],"install":[{"cmd":"pip install types-boto3-kms boto3","lang":"bash","label":"Standalone installation"},{"cmd":"pip install 'types-boto3[kms]' boto3","lang":"bash","label":"As an extra with types-boto3"}],"dependencies":[{"reason":"Runtime dependency; this package provides type stubs for boto3.","package":"boto3","optional":false},{"reason":"Recommended for static type checking integration.","package":"mypy","optional":true}],"imports":[{"note":"Importing KMSClient directly without `TYPE_CHECKING` will make `types-boto3-kms` a runtime dependency, which is usually unnecessary and adds overhead.","symbol":"KMSClient","correct":"from typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from mypy_boto3_kms.client import KMSClient"},{"note":"Specific TypeDefs provide precise type checking for boto3 response structures.","symbol":"ListKeysResponseTypeDef","correct":"from typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from mypy_boto3_kms.type_defs import ListKeysResponseTypeDef"}],"quickstart":{"code":"from typing import TYPE_CHECKING, List\nimport boto3\n\nif TYPE_CHECKING:\n    from mypy_boto3_kms.client import KMSClient\n    from mypy_boto3_kms.type_defs import KeyListEntryTypeDef, ListKeysResponseTypeDef\n\ndef get_kms_key_ids() -> List[str]:\n    \"\"\"Lists all KMS key IDs in the current AWS account.\"\"\"\n    kms_client: KMSClient = boto3.client(\"kms\")\n    \n    # The response object is type-hinted for better autocompletion and error checking\n    response: ListKeysResponseTypeDef = kms_client.list_keys()\n    \n    key_ids: List[str] = []\n    for key_entry in response.get(\"Keys\", []):\n        # key_entry is inferred as KeyListEntryTypeDef\n        if 'KeyId' in key_entry:\n            key_ids.append(key_entry['KeyId'])\n            \n    return key_ids\n\n# To run this function, ensure AWS credentials are configured (e.g., via environment variables, AWS CLI, or IAM role).\n# print(get_kms_key_ids())\n","lang":"python","description":"This quickstart demonstrates how to use `types-boto3-kms` to add type hints to a `boto3` KMS client. It shows how to import and apply type annotations for the client object and its response structures, enabling static analysis and IDE assistance for KMS API calls. Requires AWS credentials configured to execute."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Python 3.8 support has been removed in `mypy-boto3-builder` version 8.12.0 (and thus `types-boto3-kms`). Projects using Python 3.8 will not receive updates or new packages.","severity":"breaking","affected_versions":">=8.12.0"},{"fix":"Uninstall `mypy-boto3` and install `types-boto3-kms` for specific service stubs, or `types-boto3[all]` for all services.","message":"The legacy `mypy-boto3` package, which contained stubs for all services in one package, has been deprecated in favor of the modular `types-boto3` and service-specific packages like `types-boto3-kms`.","severity":"deprecated","affected_versions":"All versions since `types-boto3` was introduced as successor."},{"fix":"Always wrap type-only imports within an `if TYPE_CHECKING:` block, as shown in the quickstart and import examples.","message":"Forgetting the `if TYPE_CHECKING:` guard when importing client types (e.g., `from mypy_boto3_kms.client import KMSClient`) can inadvertently make `types-boto3-kms` a runtime dependency for your application, which is unnecessary and adds overhead.","severity":"gotcha","affected_versions":"All"},{"fix":"Consider using `types-boto3-lite` (e.g., `pip install types-boto3-lite[kms]`) which is more RAM-friendly but requires explicit type annotations, until the PyCharm issue is resolved.","message":"PyCharm's performance can be slow with `Literal` overloads in `mypy-boto3` packages (issue PY-40997). This can lead to sluggish autocompletion or analysis.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the correct stub package: `pip install types-boto3-kms` (for KMS only) or `pip install 'types-boto3[all]'` (for all services). Ensure Mypy is configured correctly in your project.","cause":"The `types-boto3` or service-specific stub package (`types-boto3-kms`) is not installed or Mypy is not configured to find it.","error":"Cannot find type stub for 'boto3'"},{"fix":"Ensure `types-boto3-kms` is installed and use the correct import path from `mypy_boto3_kms.client` within a `TYPE_CHECKING` block. Example: `if TYPE_CHECKING: from mypy_boto3_kms.client import KMSClient`.","cause":"This error typically occurs when attempting to use a type hint like `botocore.client.KMS` directly, or when the type stubs are not properly recognized by the static analyzer or IDE.","error":"Module 'botocore.client' has no attribute 'KMS'"},{"fix":"Import the specific `TypeDef` from `mypy_boto3_kms.type_defs` (e.g., `from mypy_boto3_kms.type_defs import CreateKeyRequestTypeDef`) and explicitly construct your dictionary to match its structure.","cause":"You are passing a plain Python dictionary where `mypy-boto3` expects a specific `TypedDict` from the stub package, leading to a type mismatch.","error":"Argument of type 'Dict[str, Any]' cannot be assigned to parameter of type 'MyRequestTypeDef'"}]}