Kafka Connect Python Client

1.0.0 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import os
from kafka_connect import KafkaConnect

# Ensure KAFKA_CONNECT_URL is set in your environment
# e.g., export KAFKA_CONNECT_URL="http://localhost:8083"
connect_url = os.environ.get('KAFKA_CONNECT_URL', 'http://localhost:8083')

try:
    client = KafkaConnect(connect_url)
    print(f"Connected to Kafka Connect at: {client.base_url}")

    # Get Kafka Connect cluster version
    version_info = client.get_connect_version()
    print(f"Kafka Connect Version: {version_info.get('version')}")

    # List active connectors
    connectors = client.get_connectors()
    if connectors:
        print(f"Active connectors: {', '.join(connectors)}")
    else:
        print("No active connectors found.")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure the Kafka Connect REST API is running and accessible at the configured URL.")

view raw JSON →