{"id":9863,"library":"kafka-connect-py","title":"Kafka Connect Python Client","description":"kafka-connect-py is a Python client library for interacting with the Confluent Platform Kafka Connect REST API. It provides a convenient way to manage Kafka Connect clusters, including listing, creating, updating, and deleting connectors. The current stable version is 1.0.0, and releases appear to be infrequent, driven by new feature additions or maintenance.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/aidanmelen/kafka-connect-py","tags":["kafka","connect","client","api","confluent"],"install":[{"cmd":"pip install kafka-connect-py","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"KafkaConnect","correct":"from kafka_connect import KafkaConnect"}],"quickstart":{"code":"import os\nfrom kafka_connect import KafkaConnect\n\n# Ensure KAFKA_CONNECT_URL is set in your environment\n# e.g., export KAFKA_CONNECT_URL=\"http://localhost:8083\"\nconnect_url = os.environ.get('KAFKA_CONNECT_URL', 'http://localhost:8083')\n\ntry:\n    client = KafkaConnect(connect_url)\n    print(f\"Connected to Kafka Connect at: {client.base_url}\")\n\n    # Get Kafka Connect cluster version\n    version_info = client.get_connect_version()\n    print(f\"Kafka Connect Version: {version_info.get('version')}\")\n\n    # List active connectors\n    connectors = client.get_connectors()\n    if connectors:\n        print(f\"Active connectors: {', '.join(connectors)}\")\n    else:\n        print(\"No active connectors found.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure the Kafka Connect REST API is running and accessible at the configured URL.\")","lang":"python","description":"Initialize the KafkaConnect client, retrieve the cluster version, and list existing connectors. Requires the `KAFKA_CONNECT_URL` environment variable to be set to the base URL of your Kafka Connect REST API."},"warnings":[{"fix":"Verify the `KAFKA_CONNECT_URL` environment variable or the URL passed to the `KafkaConnect` constructor. Use `try-except requests.exceptions.ConnectionError` for robust error handling.","message":"The client raises `requests.exceptions.ConnectionError` if the Kafka Connect REST API URL is incorrect, unreachable, or the service is down. Always ensure the `KAFKA_CONNECT_URL` is correct and the Kafka Connect cluster is running.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement specific error handling for `requests.exceptions.HTTPError` and check the status code (e.g., `if e.response.status_code == 404:`). Consider listing connectors (`client.get_connectors()`) before attempting operations on specific ones.","message":"When interacting with non-existent connectors (e.g., calling `get_connector_status('my_non_existent_connector')`), the Kafka Connect API typically returns a 404 Not Found response. The client translates this into a `requests.exceptions.HTTPError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Catch `requests.exceptions.HTTPError` and inspect `e.response.json()` (if JSON) or `e.response.text` for the specific validation errors from the Kafka Connect cluster. Correct your connector configuration dictionary accordingly.","message":"Invalid connector configurations (e.g., missing required fields, invalid values) passed to `create_connector` or `update_connector_config` will result in a `requests.exceptions.HTTPError` (typically 400 Bad Request). The underlying Kafka Connect API provides detailed error messages in the response body.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Double-check the `KAFKA_CONNECT_URL` environment variable or the URL provided to `KafkaConnect`. Ensure the Kafka Connect cluster is running and accessible from the machine where your Python code is executed. Verify firewall rules or network configuration if necessary.","cause":"The Python client could not establish a connection to the Kafka Connect REST API. This often means the API URL is wrong, the network is blocking the connection, or the Kafka Connect service is not running or accessible.","error":"requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))"},{"fix":"Verify the connector name for typos. Before attempting operations, you can list existing connectors using `client.get_connectors()` to confirm its presence. Implement `try-except` blocks to handle 404 errors gracefully.","cause":"You attempted an operation (like getting status, pausing, or resuming) on a Kafka Connect connector name that does not exist on the connected cluster.","error":"requests.exceptions.HTTPError: 404 Client Error: Not Found for url: http://localhost:8083/connectors/my_missing_connector/status"},{"fix":"Inspect the error response body for detailed validation messages from the Kafka Connect API. When catching the `HTTPError`, access `e.response.json()` or `e.response.text` to read the specific reasons for the 'Bad Request' and adjust your connector configuration dictionary.","cause":"This error, often occurring during `create_connector` or `update_connector_config`, indicates that the provided connector configuration is invalid based on the Kafka Connect cluster's validation rules (e.g., missing required properties, incorrect plugin names, invalid values).","error":"requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:8083/connectors"}]}