{"id":3106,"library":"mypy-boto3-kafka","title":"Type annotations for boto3 Kafka","description":"mypy-boto3-kafka provides type annotations for the AWS boto3 Kafka service. It is a generated library, currently at version 1.42.65, built with mypy-boto3-builder 8.12.0. Its release cadence generally follows updates to the underlying boto3 library and the builder.","status":"active","version":"1.42.65","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["type-stubs","boto3","aws","kafka","mypy","typing","aws-msk"],"install":[{"cmd":"pip install mypy-boto3-kafka","lang":"bash","label":"Install specific Kafka service stubs"},{"cmd":"pip install boto3-stubs[kafka]","lang":"bash","label":"Install Kafka stubs as part of boto3-stubs extras"}],"dependencies":[{"reason":"Provides the runtime functionality for which these are type stubs.","package":"boto3","optional":false}],"imports":[{"note":"Import the specific client type for Kafka service.","symbol":"KafkaClient","correct":"from mypy_boto3_kafka import KafkaClient"},{"note":"Import specific TypedDicts for request/response bodies.","symbol":"AmazonMskClusterTypeDef","correct":"from mypy_boto3_kafka.type_defs import AmazonMskClusterTypeDef"},{"note":"Import specific Literal types for allowed string values.","symbol":"BrokerAZDistributionType","correct":"from mypy_boto3_kafka.literals import BrokerAZDistributionType"}],"quickstart":{"code":"import os\nimport boto3\nfrom mypy_boto3_kafka import KafkaClient\n\n# Ensure boto3 is configured, e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME env vars\n\nregion = os.environ.get('AWS_REGION_NAME', 'us-east-1')\n\ndef get_kafka_client() -> KafkaClient:\n    session = boto3.Session(region_name=region)\n    client: KafkaClient = session.client('kafka')\n    return client\n\nkafka_client = get_kafka_client()\nresponse = kafka_client.list_clusters_v2()\n\nprint(f\"Kafka Clusters: {response.get('ClusterInfoList')}\")","lang":"python","description":"Demonstrates how to import and use the KafkaClient type stub with a standard boto3 session to get type-hinted AWS MSK operations."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher. The library specifies `requires_python: >=3.9`.","message":"The underlying mypy-boto3-builder (version 8.12.0) has removed support for Python 3.8. Therefore, mypy-boto3-kafka no longer supports Python 3.8.","severity":"breaking","affected_versions":"mypy-boto3-kafka >= 1.42.65 (built with mypy-boto3-builder 8.12.0)"},{"fix":"Review explicit `TypeDef` imports and usage, updating names according to the new conventions if affected. Most users relying on IDE auto-completion for these should adapt automatically.","message":"mypy-boto3-builder version 8.9.0 introduced breaking changes to `TypeDef` naming conventions. Type definitions for packed method arguments use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).","severity":"breaking","affected_versions":"mypy-boto3-kafka versions built with mypy-boto3-builder >= 8.9.0"},{"fix":"Ensure `boto3` is installed alongside `mypy-boto3-kafka` (e.g., `pip install boto3 mypy-boto3-kafka`).","message":"This package provides only type stubs. For actual runtime functionality, you must also install and configure the `boto3` library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For `mypy-boto3-kafka`, consider using the `types-boto3-lite[kafka]` package or disabling PyCharm's type checker and relying on an external tool like `mypy` or `pyright`.","message":"When using PyCharm, performance issues with `Literal` overloads might occur. It's recommended to disable PyCharm's internal type checker or use `boto3-stubs-lite` variants for better performance.","severity":"gotcha","affected_versions":"All versions (PyCharm specific)"},{"fix":"Use a pattern like:\n```python\nfrom typing import TYPE_CHECKING\nif TYPE_CHECKING:\n    from mypy_boto3_kafka import KafkaClient\nelse:\n    KafkaClient = object\n\n# Use KafkaClient\n```","message":"For Pylint compatibility and to avoid runtime dependencies on type stubs, it is common to guard imports with `if TYPE_CHECKING:` and set types to `object` in the `else` branch. Pylint might otherwise complain about undefined variables.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}