Google Cloud Orchestration Airflow API Client Library
Cloud Composer is a fully managed Apache Airflow service that simplifies the creation, scheduling, monitoring, and management of workflows. This client library provides programmatic access to the Google Cloud Orchestration Airflow API, allowing Python developers to interact with Cloud Composer environments and their underlying Airflow instances. The current version is 1.20.0, and Google Cloud client libraries typically follow a continuous release cadence with frequent updates for new features, bug fixes, and API changes.
Warnings
- breaking When upgrading Cloud Composer or Airflow versions, ensure your existing DAGs and any custom PyPI packages are compatible. Incompatible changes can cause DAGs to fail. It's crucial to check the changelogs for the new Airflow version and associated provider packages.
- gotcha The library's logging events are not handled by default and may contain sensitive information. Users must explicitly configure Python's standard logging functionality to capture and handle these events.
- breaking The `apache-airflow-providers-google` package, which is heavily used by Cloud Composer users, has undergone several breaking changes, including the removal or renaming of various operators and hooks (e.g., `LifeSciencesRunPipelineOperator`, `BigQueryCreateEmptyTableOperator`).
- deprecated Python versions 3.6 and below are no longer supported. Using an unsupported Python version can lead to installation failures, runtime errors, and security vulnerabilities.
Install
-
pip install google-cloud-orchestration-airflow
Imports
- EnvironmentsClient
from google.cloud.orchestration.airflow.service.v1 import EnvironmentsClient
- types
from google.cloud.orchestration.airflow.service.v1 import types
Quickstart
import os
from google.cloud.orchestration.airflow.service.v1 import EnvironmentsClient
from google.cloud.orchestration.airflow.service.v1 import types
def list_composer_environments(project_id: str, location: str):
"""Lists Cloud Composer environments in a given project and location."""
client = EnvironmentsClient()
parent = f"projects/{project_id}/locations/{location}"
try:
request = types.ListEnvironmentsRequest(parent=parent)
page_result = client.list_environments(request=request)
print(f"Cloud Composer Environments in {location}:")
found_any = False
for environment in page_result:
print(f" - {environment.name} (State: {environment.state.name})")
found_any = True
if not found_any:
print(" No environments found.")
except Exception as e:
print(f"Error listing environments: {e}")
if __name__ == "__main__":
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-gcp-project-id')
location = os.environ.get('GOOGLE_CLOUD_LOCATION', 'us-central1') # e.g., 'us-central1', 'europe-west1'
if project_id == 'your-gcp-project-id':
print("Please set the GOOGLE_CLOUD_PROJECT environment variable or replace 'your-gcp-project-id'.")
elif location == 'us-central1':
print("Please set the GOOGLE_CLOUD_LOCATION environment variable or choose your desired location.")
else:
list_composer_environments(project_id, location)