Registry / gcp / google-cloud-managedkafka

google-cloud-managedkafka

JSON →
library0.4.1pypypi✓ verified 24d ago

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-managedkafka
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-MANAG
G
google-cloud-managedkafka
gcppythonv0.4.1
Install
5.6s avg
Import
1546ms
Disk
69MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.826s · 70.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.6s · import 1.266s · 69MB
69MB installed
● package 69MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ManagedKafkaClient
from google.cloud.managedkafka_v1 import ManagedKafkaClient

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.

import os from google.cloud.managedkafka_v1 import ManagedKafkaClient # Set your Google Cloud project ID and location # Ensure these environment variables are set or replace with actual values project_id = os.environ.get("GCP_PROJECT_ID", "your-gcp-project-id") location_id = os.environ.get("GCP_LOCATION_ID", "us-central1") # e.g., us-central1 # Construct the parent resource name parent = f"projects/{project_id}/locations/{location_id}" client = ManagedKafkaClient() try: print(f"Listing Managed Kafka clusters in {parent}...") # The 'parent' parameter expects a string in the format 'projects/PROJECT_ID/locations/LOCATION_ID' clusters = client.list_clusters(parent=parent) found_clusters = False for cluster in clusters: print(f" - Cluster name: {cluster.name}, Capacity: {cluster.capacity_config.vcpu_count} vCPUs") found_clusters = True if not found_clusters: print(" No clusters found. Ensure you have clusters deployed in this location.") except Exception as e: print(f"An error occurred: {e}") print("Ensure you have authenticated (e.g., `gcloud auth application-default login`)") print("and have sufficient IAM permissions (e.g., `roles/managedkafka.viewer`).")
Debug
Known issues
gotchaGoogle Cloud client libraries require proper authentication. The quickstart assumes `gcloud auth application-default login` has been run or `GOOGLE_APPLICATION_CREDENTIALS` is set. Without valid credentials, API calls will fail with authentication errors.
fix
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.
affects: All versions
gotchaResource names for Google Cloud APIs follow a specific, hierarchical string format (e.g., `projects/PROJECT_ID/locations/LOCATION_ID/clusters/CLUSTER_ID`). Incorrect formatting will lead to `google.api_core.exceptions.InvalidArgument` errors.
fix
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.
affects: All versions
gotchaAs a `0.x.x` version library, the API surface may evolve more rapidly than `1.x.x` or higher versions. While Google strives for stability, minor updates might introduce non-breaking changes or new features that could subtly alter behavior or require updates to your code for new patterns.
fix
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.
affects: 0.x.x versions
Errors
Common errors & fixes
Authentication failed: Invalid username or password
The service account or user account used to connect to Google Cloud Managed Kafka lacks the necessary IAM permissions (e.g., 'roles/managedkafka.client') or the authentication credentials are misconfigured or expired.
fix
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).
ModuleNotFoundError: No module named 'google.cloud.managedkafka'
The `google-cloud-managedkafka` Python client library has not been installed in the current Python environment, or the environment where the code is being run does not have access to the installed package.
fix
Install the library using pip: `pip install google-cloud-managedkafka`. Ensure your Python environment is correctly activated if using a virtual environment.
kafka client has run out of available brokers to talk unexpected EOF
The Kafka client (which is separate from the `google-cloud-managedkafka` *management* library) cannot establish a connection with the Google Cloud Managed Kafka brokers. This often indicates network connectivity issues (firewall, VPC configuration), incorrect bootstrap server addresses, or incompatible client/broker versions.
fix
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.
ImportError: cannot import name 'KafkaProducer' from 'google.cloud.managedkafka'
Developers mistakenly attempt to import a Kafka client-specific class like `KafkaProducer` (used for message production) from the `google-cloud-managedkafka` library. This library is designed for *managing* Google Cloud Managed Kafka resources (clusters, topics, consumer groups), not for direct message production or consumption.
fix
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.
Upgrade
Version history
0.4.1latest on PyPI · released Jun 22, 2026
Audit
Dependencies
google-api-corerequiredCore utilities for Google APIs, including gRPC handling.
google-authrequiredHandles authentication with Google Cloud services.
proto-plusrequiredProvides Pythonic wrappers around Protocol Buffer messages.
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
google-cloud-managedkafka — pip install google-cloud-managedkafka · libregistry