Google Cloud Workflows Client Library

1.21.0 · active · verified Sat Mar 28

The `google-cloud-workflows` Python client library, currently at version 1.21.0, allows developers to orchestrate and automate Google Cloud and HTTP-based API services with serverless workflows. It provides a programmatic interface for creating, deploying, and managing workflows. Google Cloud client libraries typically follow a frequent release cadence, with updates addressing new features, bug fixes, and API changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a new execution for an existing Google Cloud Workflow using the client library. It assumes you have authenticated via Application Default Credentials (e.g., `gcloud auth application-default login`) and that a workflow named `my-first-workflow` exists in `us-central1`. Replace placeholder values with your actual project ID, location, and workflow name. The example passes a JSON argument to the workflow.

import os
import json
from google.cloud.workflows_v1 import WorkflowsClient
from google.cloud.workflows.executions_v1 import ExecutionsClient
from google.cloud.workflows.executions_v1.types.executions import Execution

# Set your Google Cloud Project ID, region, and existing workflow name
PROJECT_ID = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')
LOCATION = os.environ.get('GOOGLE_CLOUD_LOCATION', 'us-central1')
WORKFLOW_NAME = os.environ.get('GOOGLE_CLOUD_WORKFLOW_NAME', 'my-first-workflow')

# Initialize clients
workflows_client = WorkflowsClient()
executions_client = ExecutionsClient()

# Construct the parent path for the workflow
parent_path = workflows_client.workflow_path(PROJECT_ID, LOCATION, WORKFLOW_NAME)

# Define optional runtime arguments for the workflow (as a JSON string)
runtime_arguments = {
    "name": "World"
}

# Create an execution instance
execution = Execution(argument=json.dumps(runtime_arguments))

print(f"Creating execution for workflow: {WORKFLOW_NAME} in {LOCATION}...")
# Send the request to create the execution
response = executions_client.create_execution(parent=parent_path, execution=execution)

print(f"Created execution: {response.name} with state: {response.state.name}")
print("To view the execution in the console, visit:")
print(f"https://console.cloud.google.com/workflows/executions/{LOCATION}/{WORKFLOW_NAME}/{response.name.split('/')[-1]}?project={PROJECT_ID}")

view raw JSON →