{"id":1496,"library":"google-cloud-managedkafka","title":"Google Cloud Managed Kafka","description":"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.","status":"active","version":"0.4.0","language":"python","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-managedkafka","tags":["google-cloud","kafka","managed-service","gcp"],"install":[{"cmd":"pip install google-cloud-managedkafka","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core utilities for Google APIs, including gRPC handling.","package":"google-api-core"},{"reason":"Handles authentication with Google Cloud services.","package":"google-auth"},{"reason":"Provides Pythonic wrappers around Protocol Buffer messages.","package":"proto-plus"}],"imports":[{"symbol":"ManagedKafkaClient","correct":"from google.cloud.managedkafka_v1 import ManagedKafkaClient"}],"quickstart":{"code":"import os\nfrom google.cloud.managedkafka_v1 import ManagedKafkaClient\n\n# Set your Google Cloud project ID and location\n# Ensure these environment variables are set or replace with actual values\nproject_id = os.environ.get(\"GCP_PROJECT_ID\", \"your-gcp-project-id\")\nlocation_id = os.environ.get(\"GCP_LOCATION_ID\", \"us-central1\") # e.g., us-central1\n\n# Construct the parent resource name\nparent = f\"projects/{project_id}/locations/{location_id}\"\n\nclient = ManagedKafkaClient()\n\ntry:\n    print(f\"Listing Managed Kafka clusters in {parent}...\")\n    # The 'parent' parameter expects a string in the format 'projects/PROJECT_ID/locations/LOCATION_ID'\n    clusters = client.list_clusters(parent=parent)\n    found_clusters = False\n    for cluster in clusters:\n        print(f\"  - Cluster name: {cluster.name}, Capacity: {cluster.capacity_config.vcpu_count} vCPUs\")\n        found_clusters = True\n    if not found_clusters:\n        print(\"  No clusters found. Ensure you have clusters deployed in this location.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure you have authenticated (e.g., `gcloud auth application-default login`)\")\n    print(\"and have sufficient IAM permissions (e.g., `roles/managedkafka.viewer`).\")","lang":"python","description":"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."},"warnings":[{"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.","message":"Google 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Resource 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"As 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.","severity":"gotcha","affected_versions":"0.x.x versions"}],"env_vars":null,"search_vec":"'0.4.0':33 'access':36 'allow':14 'apach':25 'api':27,61 'cadenc':54 'chang':62 'client':10 'cloud':2,8,21,46,50,65 'cluster':40 'consum':43 'current':30 'develop':15 'follow':48 'frequent':52 'gcp':70 'googl':1,7,20,45,49,64 'google-cloud':63 'google-cloud-managedkafka':6 'interact':17 'kafka':4,26,39,66 'librari':11,29 'manag':3,22,38,68 'managed-servic':67 'managedkafka':9 'often':57 'programmat':35 'provid':34 'python':13 'releas':53 'servic':23,69 'tie':58 'topic':41 'under':60 'updat':56 'version':32 'within':44","created_at":"2026-04-09T03:50:26.404690+00:00","updated_at":"2026-04-16T15:22:30.760771+00:00","problems":[{"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).","cause":"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.","error":"Authentication failed: Invalid username or password"},{"fix":"Install the library using pip: `pip install google-cloud-managedkafka`. Ensure your Python environment is correctly activated if using a virtual environment.","cause":"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.","error":"ModuleNotFoundError: No module named 'google.cloud.managedkafka'"},{"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.","cause":"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.","error":"kafka client has run out of available brokers to talk unexpected EOF"},{"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.","cause":"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.","error":"ImportError: cannot import name 'KafkaProducer' from 'google.cloud.managedkafka'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.4.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/googleapis/google-cloud-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/google-cloud-managedkafka/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["gcp","aws"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}