Google Cloud AutoML Client Library
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
- deprecated Google strongly recommends migrating to the Vertex AI SDK for Python (`google-cloud-aiplatform`) for new machine learning development. The `google-cloud-automl` library primarily targets an older generation of AutoML tools. While this library remains functional, future feature development, enhanced capabilities, and the best user experience are focused within Vertex AI.
- breaking This library requires Python >= 3.7. Versions prior to 3.7 are not supported. Specifically, the last version compatible with Python 3.6 is `google-cloud-automl==2.7.3`, and Python 2.7 support ended with `google-cloud-automl==1.0.1`.
- gotcha Proper authentication and IAM permissions are crucial for interacting with the AutoML API. Common issues include the AutoML API not being enabled in the Google Cloud project, an incorrect service account lacking necessary roles (e.g., `roles/automl.editor`), or the `GOOGLE_APPLICATION_CREDENTIALS` environment variable not being correctly set to point to your service account key file. This is especially prone to error in non-standard execution environments like Jupyter notebooks.
Install
-
pip install google-cloud-automl
Imports
- AutoMlClient
from google.cloud import automl_v1 client = automl_v1.AutoMlClient()
Quickstart
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)