Registry / gcp / google-cloud-run

google-cloud-run

JSON →
library0.16.1pypypi✓ verified 24d ago

The `google-cloud-run` Python library is the official client library for interacting with the Google Cloud Run Admin API. It enables developers to programmatically manage Cloud Run services and jobs, including deployment, configuration, and monitoring. Currently at version 0.16.0, this library is part of the larger `google-cloud-python` monorepo and receives frequent updates, typically with a release cadence aligning with other Google Cloud client libraries.

pip install google-cloud-run
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-RUN
G
google-cloud-run
gcppythonv0.16.1
Install
5.7s avg
Import
1757ms
Disk
72MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.16.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 2.134s · 73.5MB
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.

ServicesClient
from google.cloud.run_v2 import ServicesClient
JobsClient
from google.cloud.run_v2 import JobsClient

This quickstart demonstrates how to instantiate the `ServicesClient` and list existing Cloud Run services within a specified Google Cloud project and location. Ensure your environment is authenticated (e.g., via `gcloud auth application-default login` or by setting `GOOGLE_APPLICATION_CREDENTIALS`) and that `GOOGLE_CLOUD_PROJECT_ID` and `GOOGLE_CLOUD_LOCATION` environment variables are set.

import os from google.cloud.run_v2 import ServicesClient def list_cloud_run_services(project_id: str, location: str): """Lists Cloud Run services in a given project and location.""" client = ServicesClient() parent = f"projects/{project_id}/locations/{location}" try: # Paged iteration over services print(f"Fetching services for parent: {parent}") for service in client.list_services(parent=parent): print(f"Service Name: {service.name}") print(f" URI: {service.uri}") # You can access more service attributes here, e.g., service.traffic print("-" * 20) except Exception as e: print(f"Error listing services: {e}") if __name__ == "__main__": # Set your Google Cloud Project ID and desired location # Ensure GOOGLE_APPLICATION_CREDENTIALS is set or you are running in a GCP environment # e.g., 'export GOOGLE_CLOUD_PROJECT_ID="your-project"' # e.g., 'export GOOGLE_CLOUD_LOCATION="us-central1"' project_id = os.environ.get("GOOGLE_CLOUD_PROJECT_ID", "your-project-id") location = os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1") if project_id == "your-project-id": print("Please set the GOOGLE_CLOUD_PROJECT_ID environment variable or replace 'your-project-id' in the script.") else: list_cloud_run_services(project_id, location)
Debug
Known issues
gotchaThe `google-cloud-run` library primarily targets the Cloud Run Admin API v2. Ensure you are using the correct client for the API version you intend to interact with, as API object structures and methods may differ significantly between v1 and v2, potentially leading to `TypeError` or unexpected behavior.
fix
Consult the official client library documentation (e.g., `google.cloud.run_v2`) and the Cloud Run Admin API documentation to confirm the correct API version and client methods for your use case.
affects: All versions
gotchaWhen constructing resource names for services or jobs (e.g., in `get_service` or `create_service` calls), ensure they follow the expected format: `projects/{project_id}/locations/{location}/services/{service_id}`. Incorrect formatting can result in `NotFound` or `InvalidArgument` errors.
fix
Always use f-strings or `.format()` to construct resource names dynamically, ensuring all path components (project ID, location, service ID) are correctly included and ordered. For example, `parent = f"projects/{project_id}/locations/{location}"`.
affects: All versions
gotchaThe library uses standard Python logging, but by default, logging events are not handled, and logs may contain sensitive information. For visibility and security, you must explicitly configure logging or set the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable.
fix
To enable default logging, set the `GOOGLE_SDK_PYTHON_LOGGING_SCOPE` environment variable to `google` or `google.cloud.run_v2`. For advanced configuration, use Python's `logging` module to set up handlers and formatters, e.g., `logging.basicConfig(level=logging.INFO)`.
affects: All versions
gotchaUsing the client library to manage Cloud Run resources requires appropriate IAM permissions on the Google Cloud project and specific resources. Lack of permissions will result in `PermissionDenied` errors.
fix
Grant the service account or user credentials used by your application the necessary IAM roles, such as 'Cloud Run Admin' (`roles/run.admin`) or more granular roles like 'Cloud Run Developer' (`roles/run.developer`) for deployment, or 'Cloud Run Viewer' (`roles/run.viewer`) for read-only access.
affects: All versions
gotchaOperations with the client library often require a Google Cloud project ID. If not explicitly provided in client constructors or method calls, the library attempts to infer it from environment variables (e.g., `GOOGLE_CLOUD_PROJECT`, `GCP_PROJECT`, `PROJECT_ID`, or `GOOGLE_CLOUD_PROJECT_ID`) or application default credentials. Failing to provide a valid project ID will prevent resource lookup or creation, leading to errors like `NotFound`, `InvalidArgument`, or specific error messages prompting you to set the project ID.
fix
Ensure the Google Cloud Project ID is accessible to the client library. The most common methods are: 1. Setting the `GOOGLE_CLOUD_PROJECT` environment variable (or other recognized variables like `GOOGLE_CLOUD_PROJECT_ID`). 2. Explicitly passing `project='your-project-id'` to the client constructor (e.g., `run_v2.ServicesClient(project='your-project-id')`) or relevant method calls.
affects: All versions
gotchaThe Cloud Run client library requires a Google Cloud project ID to identify the target project. This is often provided via the `GOOGLE_CLOUD_PROJECT_ID` environment variable or directly in API calls. Not providing it will result in errors indicating a missing project identifier or invalid resource names.
fix
Set the `GOOGLE_CLOUD_PROJECT_ID` environment variable (or `GCLOUD_PROJECT`, `GOOGLE_CLOUD_PROJECT`) before running your application, or ensure the project ID is explicitly passed to relevant client methods or during client initialization.
affects: All versions
Errors
Common errors & fixes
Revision REVISION_NAME is not ready and cannot serve traffic. The user provided container failed to start and listen on port defined by PORT=8080 environment variable
The Python application inside your container is not listening on the port specified by the PORT environment variable (which defaults to 8080 on Cloud Run), or it encountered a critical error during startup that prevented it from becoming ready to serve requests.
fix
Ensure your Python application binds to all network interfaces (`0.0.0.0`) and the port specified by the `PORT` environment variable. For example, using a common web framework like Flask: `app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))`. Check your application logs for specific startup errors.
ModuleNotFoundError: No module named 'google.cloud'
This error indicates that the `google-cloud-run` library or one of its core `google.cloud` dependencies is not correctly installed within your container image or the Python environment where your code is executing on Cloud Run.
fix
Add `google-cloud-run` (and any other necessary `google-cloud` libraries) to your `requirements.txt` file and ensure that `pip install -r requirements.txt` is run during your Docker image build process or by the Cloud Run buildpacks if deploying from source.
PERMISSION_DENIED: User must have permission to read the image
The service account or user attempting to deploy the Cloud Run service lacks the necessary Identity and Access Management (IAM) permissions to access the container image stored in Artifact Registry or Container Registry, or to perform other required deployment actions.
fix
Grant the appropriate IAM roles to the deploying identity or the Cloud Run service agent. This often includes `roles/storage.objectViewer` for accessing the image, and `roles/run.admin` or `roles/run.developer` for managing Cloud Run services, on the respective project or repository.
AttributeError: module 'collections' has no attribute 'Mapping'
This specific error occurs when the `gcloud` SDK, which uses Python internally, encounters a compatibility issue with its internal dependencies or your system's Python version (typically Python 3.10 or newer) where `collections.Mapping` has been moved or removed.
fix
Update your Google Cloud SDK components by running `gcloud components update`. If the issue persists, consider ensuring `gcloud` uses a compatible Python version, potentially by setting a specific Python executable in your environment or reinstalling the SDK.
ERROR: failed to launch: direct exec: no such file or directory
When running a Cloud Run Job, the executable command or script specified as the entry point in your container image (or in the job configuration) cannot be found or is incorrectly configured, which often happens when adapting a service container for a job.
fix
Verify the `ENTRYPOINT` or `CMD` instruction in your Dockerfile, or the `--command` and `--args` parameters in your `gcloud run jobs deploy` command, to ensure they point to a valid, executable file within the container and provide the correct arguments for a standalone job execution.
Upgrade
Version history
0.16.1latest on PyPI · released Jun 22, 2026
Audit
Dependencies
google-api-corerequiredCore library for Google API clients
google-authrequiredHandles authentication with Google Cloud
google-protobufrequiredProtocol buffers for API communication
googleapis-common-protosrequiredCommon protocol buffer definitions for Google APIs
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
2
Resources