The `google-cloud-managedkafka` client library for Python allows developers to interact with the Google Cloud Managed Service for Apache Kafka API. This library, currently at version `0.4.0`, provides programmatic access to manage Kafka clusters, topics, and consumers within Google Cloud. It follows Google Cloud's frequent release cadence, with updates often tied to underlying API changes.
pip install google-cloud-managedkafkaVerified import paths — ran on the pinned version, not inferred.
Initializes the ManagedKafkaClient and attempts to list existing Managed Kafka clusters in a specified Google Cloud project and location. This example demonstrates basic client instantiation and API interaction.
Authenticate your environment by running `gcloud auth application-default login` or by setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of a service account key file.
Always construct resource names using the prescribed format, often with helper methods or f-strings as shown in the quickstart, ensuring all components (project ID, location ID, resource ID) are correctly included.
Pin your dependency to a specific minor version (e.g., `google-cloud-managedkafka==0.4.*`) in your `requirements.txt` to ensure consistent behavior. Regularly review release notes when updating to new minor versions.
Ensure the authenticating principal has the `roles/managedkafka.client` IAM role on the project containing the cluster and that Application Default Credentials (ADC) are correctly set up (e.g., by running `gcloud auth application-default login` for local development or attaching a service account to the compute resource).
Install the library using pip: `pip install google-cloud-managedkafka`. Ensure your Python environment is correctly activated if using a virtual environment.
Verify network connectivity between your client and the Kafka brokers (check firewall rules, VPC settings). Ensure the bootstrap server addresses in your Kafka client configuration are correct and accessible. Also, confirm that your Kafka client version is compatible with the Managed Kafka service.
Use a dedicated, standard Kafka client library (e.g., `kafka-python` or `confluent-kafka-python`) for message production and consumption. First, install the appropriate client (e.g., `pip install kafka-python`), then import the producer from that library: `from kafka import KafkaProducer`. The `google-cloud-managedkafka` library should be used for administrative tasks only.