{"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":"en","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,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}