{"record":{"id":"70fdabfc7853d0eb","repo":"cocoindex-io/cocoindex","slug":"confluent-kafka-is-required-to-use-the-kafka-conne-70fdab","errorCode":null,"errorMessage":"confluent_kafka is required to use the Kafka connector. Please install cocoindex[kafka].","messagePattern":"confluent_kafka is required to use the Kafka connector\\. Please install cocoindex\\[kafka\\]\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/kafka/_target.py","lineNumber":18,"sourceCode":"\"\"\"\nKafka target for CocoIndex.\n\nThis module provides a two-level target state system for Kafka:\n1. Topic level: Lightweight container for generation tracking (user-managed topic)\n2. Message level: Produces messages to the topic for upserts/deletes\n\"\"\"\n\nfrom __future__ import annotations\n\nimport asyncio\nfrom dataclasses import dataclass\nfrom typing import Callable, Collection, Generic, NamedTuple, Sequence\n\ntry:\n    from confluent_kafka.aio import AIOProducer  # type: ignore[import-not-found]\nexcept ImportError as e:\n    raise ImportError(\n        \"confluent_kafka is required to use the Kafka connector. \"\n        \"Please install cocoindex[kafka].\"\n    ) from e\n\nimport cocoindex as coco\nfrom cocoindex.connectorkits.fingerprint import fingerprint_bytes, fingerprint_str\nfrom cocoindex._internal.context_keys import ContextKey, ContextProvider\nfrom cocoindex._internal.datatype import TypeChecker\n\n# --- Type aliases ---\n\n_MessageFingerprint = bytes\n\n# --- Internal types ---\n\n\nclass _TopicKey(NamedTuple):\n    producer_key: str","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/kafka/_target.py#L1-L36","documentation":"Importing the Kafka target connector module fails because confluent_kafka (specifically confluent_kafka.aio.AIOProducer) is not installed. The module wraps the import in a try/except and re-raises an ImportError telling the user to install the cocoindex[kafka] extra.","triggerScenarios":"Any import of python/cocoindex/connectors/kafka/_target.py (directly or via the kafka connectors package) when `from confluent_kafka.aio import AIOProducer` raises ImportError.","commonSituations":"Base cocoindex install without extras; environments where an older confluent_kafka version lacks confluent_kafka.aio; wheels unavailable on the platform causing install (and later import) failure.","solutions":["Install the extra: `pip install 'cocoindex[kafka]'`.","If confluent_kafka is installed but the import still fails, upgrade it (`pip install -U confluent_kafka`) — the aio submodule requires a recent version.","Verify with `python -c \"from confluent_kafka.aio import AIOProducer\"` before using the connector."],"exampleFix":"// before\nfrom cocoindex.connectors.kafka import KafkaTarget  # ImportError at import time\n// after\n# pip install 'cocoindex[kafka]'\nfrom cocoindex.connectors.kafka import KafkaTarget","handlingStrategy":"try-catch","validationCode":"try:\n    from confluent_kafka.aio import AIOProducer  # noqa: F401\nexcept ImportError:\n    raise SystemExit(\"Install the Kafka extra: pip install 'cocoindex[kafka]'\")","typeGuard":null,"tryCatchPattern":"try:\n    from cocoindex.connectors.kafka import KafkaTarget\nexcept ImportError as e:\n    if \"confluent_kafka\" in str(e):\n        raise SystemExit(\"Install: pip install 'cocoindex[kafka]'\") from e\n    raise","preventionTips":["Install cocoindex[kafka] explicitly in every environment.","Ensure confluent_kafka is recent enough to include confluent_kafka.aio.","Verify the import in a CI smoke test."],"tags":["python","kafka","optional-dependency","import-error"],"backgroundTag":"missing-optional-dependency","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}