Google Cloud AutoML Client Library

2.18.1 · active · verified Sat Mar 28

The `google-cloud-automl` Python client library provides programmatic access to the Google Cloud AutoML API, enabling developers to train high-quality machine learning models tailored to specific business needs without extensive ML expertise. It leverages Google's state-of-the-art transfer learning and Neural Architecture Search technology. Currently at version 2.18.1, the library follows a frequent release cadence, typical of Google Cloud client libraries, with new versions often published weekly or bi-weekly. While functional, Google strongly recommends migrating to the Vertex AI SDK (`google-cloud-aiplatform`) for new development, as Vertex AI represents the next generation of Google's AI platform with enhanced features and MLOps capabilities.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to list existing AutoML datasets in a specified Google Cloud project and location. Ensure your `GOOGLE_CLOUD_PROJECT` environment variable is set to your project ID, and `GOOGLE_CLOUD_LOCATION` (defaulting to `us-central1`) is set to the desired region. You must also have the AutoML API enabled and appropriate IAM permissions (e.g., `roles/automl.viewer` or `roles/automl.editor`) for your authenticated service account.

import os
from google.cloud import automl_v1
from google.api_core.exceptions import GoogleAPIError

def list_automl_datasets(project_id: str, location: str):
    """Lists all AutoML datasets for a given project and location."""
    try:
        client = automl_v1.AutoMlClient()
        project_location = f"projects/{project_id}/locations/{location}"
        
        print(f"Listing datasets for project '{project_id}' in location '{location}'...")
        datasets = client.list_datasets(parent=project_location)
        
        found_datasets = False
        for dataset in datasets:
            found_datasets = True
            print(f"- Dataset name: {dataset.display_name} (ID: {dataset.name.split('/')[-1]})")
            print(f"  Full Resource Name: {dataset.name}")
            print(f"  State: {automl_v1.Dataset.State(dataset.example_count_state).name}")
            print(f"  Creation Time: {dataset.create_time.strftime('%Y-%m-%d %H:%M:%S UTC')}")

        if not found_datasets:
            print("No datasets found.")

    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__":
    project_id = os.environ.get("GOOGLE_CLOUD_PROJECT")
    location = os.environ.get("GOOGLE_CLOUD_LOCATION", "us-central1") # Default location

    if not project_id:
        print("Error: GOOGLE_CLOUD_PROJECT environment variable not set.")
        print("Please set it to your Google Cloud project ID.")
    else:
        list_automl_datasets(project_id, location)

view raw JSON →