Azure Machine Learning Core SDK (v1)

1.61.0.post3 · deprecated · verified Sat Apr 11

This package, part of the Azure Machine Learning Python SDK v1, provides core functionalities for interacting with Azure Machine Learning workspaces. It enables management of compute targets, experiments, runs, models, and environments. While it remains functional for existing workflows, it is officially deprecated as of March 2025 and will only receive security fixes until its end-of-support on June 30, 2026. Users are strongly encouraged to migrate to the Azure Machine Learning Python SDK v2 (`azure-ai-ml`).

Warnings

Install

Imports

Quickstart

The quickstart demonstrates how to connect to an Azure Machine Learning Workspace. The recommended approach is to use `Workspace.from_config()` which reads details from a `config.json` file, or as a fallback, explicitly provide subscription, resource group, and workspace names. Ensure you are authenticated to Azure (e.g., via `az login`) for interactive login, or use service principal/MSI for automated workflows.

import os
from azureml.core import Workspace

# Recommended: Store workspace configuration in a .azureml/config.json file
# This allows Workspace.from_config() to load details automatically.
# Example config.json:
# {
#    "subscription_id": "YOUR_SUBSCRIPTION_ID",
#    "resource_group": "YOUR_RESOURCE_GROUP_NAME",
#    "workspace_name": "YOUR_WORKSPACE_NAME"
# }

try:
    # Attempt to load workspace from local config file
    ws = Workspace.from_config()
    print(f"Workspace loaded from config: {ws.name}")
except Exception as e:
    print(f"Could not load workspace from config: {e}. Attempting direct connection...")
    # Fallback: Connect directly using environment variables or hardcoded values (not recommended for production)
    subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')
    resource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP_NAME')
    workspace_name = os.environ.get('AZURE_WORKSPACE_NAME', 'YOUR_WORKSPACE_NAME')

    if 'YOUR_' in subscription_id or 'YOUR_' in resource_group or 'YOUR_' in workspace_name:
        print("Please provide valid Azure subscription, resource group, and workspace details.")
    else:
        try:
            ws = Workspace(subscription_id=subscription_id, 
                           resource_group=resource_group, 
                           workspace_name=workspace_name)
            print(f"Workspace connected: {ws.name}")
        except Exception as auth_e:
            print(f"Failed to connect to workspace with provided credentials: {auth_e}")
            print("Ensure you are authenticated (e.g., via `az login`) and have correct details.")

# Example: Accessing workspace properties
if 'ws' in locals() and ws is not None:
    print(f"Workspace Name: {ws.name}")
    print(f"Azure Region: {ws.location}")
    print(f"Default Datastore Name: {ws.get_default_datastore().name}")

view raw JSON →