Registry / gcp / google-cloud-container

google-cloud-container

JSON →
library2.65.0pypypi✓ verified 24d ago

The `google-cloud-container` Python client library provides programmatic access to the Google Kubernetes Engine (GKE) API. It allows developers to build and manage container-based applications using the open-source Kubernetes technology. The current version is 2.63.0, and it follows a frequent release cadence as part of the broader `google-cloud-python` monorepo.

pip install google-cloud-container
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-CONTA
G
google-cloud-container
gcppythonv2.65.0
Install
5.7s avg
Import
1856ms
Disk
72MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.65.0 · 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 2.332s · 73.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 5.7s · import 1.380s · 72MB
72MB installed
● package 72MB
Code
Verified usage

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

ContainerServiceClient
from google.cloud import container_v1
from google.cloud.container_v1 import ContainerServiceClient

Initializes the Google Kubernetes Engine client and lists all clusters within a specified Google Cloud project and location (zone/region), demonstrating basic connectivity and resource retrieval. Authentication is handled automatically via Application Default Credentials (ADC) from the environment or `gcloud` CLI.

import os from google.cloud.container_v1 import ContainerServiceClient from google.api_core.exceptions import GoogleAPIError def list_gke_clusters(project_id: str, location: str = "-"): """Lists all Google Kubernetes Engine clusters in a given project and location. Args: project_id: Your Google Cloud project ID. location: The Google Cloud location (e.g., "us-central1" for a region, or "us-central1-a" for a zone). Use "-" for all locations. """ try: client = ContainerServiceClient() parent = f"projects/{project_id}/locations/{location}" # The list_clusters method is paginated, iterate through the responses response = client.list_clusters(parent=parent) if response.clusters: print(f"Clusters in project '{project_id}' and location '{location}':") for cluster in response.clusters: print(f"- Name: {cluster.name}") print(f" Location: {cluster.location}") print(f" Status: {cluster.status.name}") print(f" Endpoint: {cluster.endpoint}") else: print(f"No clusters found in project '{project_id}' and location '{location}'.") except GoogleAPIError as e: print(f"An API error occurred: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") if __name__ == "__main__": # Set your Google Cloud Project ID as an environment variable # For local development, ensure GOOGLE_APPLICATION_CREDENTIALS is set # or you've run `gcloud auth application-default login` project_id = os.environ.get("GOOGLE_CLOUD_PROJECT", "your-gcp-project-id") # Optionally specify a specific region or zone, e.g., "us-central1" or "us-central1-a" # Use "-" to list clusters across all regions/zones target_location = os.environ.get("GKE_LOCATION", "-") if project_id == "your-gcp-project-id": print("Please set the 'GOOGLE_CLOUD_PROJECT' environment variable to your project ID.") print("For example: export GOOGLE_CLOUD_PROJECT='my-project-123'") else: list_gke_clusters(project_id, target_location)
Debug
Known issues
gotchaAlways use Application Default Credentials (ADC) for authentication. Avoid hardcoding service account key files, embedding them in Docker images, or committing them to source control. For local development, use `gcloud auth application-default login`. For deployed services, rely on attached service accounts or Workload Identity.
fix
Configure ADC properly for your environment. Use environment variables like `GOOGLE_APPLICATION_CREDENTIALS` only when absolutely necessary (e.g., CI/CD outside GCP with temporary keys), and ensure they are securely managed.
affects: All
gotchaWhen interacting with GKE regional clusters, the `get_cluster` or `list_clusters` methods require specifying the `name` or `parent` field with the region, not the `zone` field. Using `zone` for a regional cluster will result in an `InvalidArgument` error.
fix
For regional clusters, construct the `parent` parameter as `projects/{project_id}/locations/{region}`. For example, `client.list_clusters(parent='projects/my-project/locations/us-central1')`.
affects: All
breakingThe `google-cloud-container` library, like other `google-cloud-python` libraries, no longer supports Python versions older than 3.7. Attempting to use it with Python 3.6 or earlier will lead to installation or runtime errors.
fix
Upgrade your Python environment to version 3.7 or newer. Python 3.7 is the minimum requirement, but generally, it's recommended to use actively maintained Python versions.
affects: <= 3.6
gotchaThe logging events from this library (and other `google-cloud-python` libraries) are subject to change. Google may refine the occurrence, level, and content of various log messages without flagging these changes as breaking. Do not depend on the immutability of specific logging events for application logic.
fix
While logging can be useful for debugging, avoid building critical application logic that relies on the exact format or content of log messages from the client library. Implement robust error handling based on API responses and exceptions.
affects: All
deprecatedIt is not recommended to install the monolithic `google-api-python-client` package if you only need specific Google Cloud services. This approach leads to larger distribution sizes and can complicate dependency management.
fix
Install only the specific `google-cloud-*` client libraries your application requires, such as `google-cloud-container` for GKE interactions.
affects: All
breakingPython 3.9 has reached its end-of-life and is no longer actively supported by `google-cloud-container` and its core dependencies (`google.api_core`, `google.auth`). Using the library with Python 3.9 will result in `FutureWarning` messages regarding unsupported Python versions and can lead to critical runtime errors, such as `ImportError`, preventing the library from functioning correctly.
fix
Upgrade your Python environment to an actively supported version. Google recommends Python 3.10 or newer.
affects: 3.9
breakingThe `ContainerServiceClient` class is no longer directly importable from `google.cloud.container_v1`. This class has been renamed to `ClusterManagerClient` and is typically imported from `google.cloud.container` or `google.cloud.container_v1.services.cluster_manager`.
fix
Update your import statement. For example, replace `from google.cloud.container_v1 import ContainerServiceClient` with `from google.cloud.container import ClusterManagerClient` or `from google.cloud.container_v1.services.cluster_manager import ClusterManagerClient`, and adjust subsequent code accordingly.
affects: All
Upgrade
Version history
2.65.0latest on PyPI · released Jun 3, 2026
Audit
Dependencies
google-api-corerequiredCore library for Google API clients
google-authrequiredHandles authentication with Google Cloud services (implicitly via Application Default Credentials)
Agent activity
39 hits · last 30 days
node
36
OpenAI (training)
1
Resources
google-cloud-container — pip install google-cloud-container · libregistry