{"id":2401,"library":"azure-ai-ml","title":"Azure AI ML Client Library","description":"The Microsoft Azure Machine Learning Client Library for Python (also known as the 'v2 SDK') is the primary Python interface for interacting with Azure Machine Learning. It enables developers to build, train, and deploy machine learning models, manage workspaces, compute resources, data, environments, and jobs programmatically. It's actively developed, with frequent releases, often on a monthly cadence, aligning with Azure service updates. The current version is 1.32.0.","status":"active","version":"1.32.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python","tags":["azure","machine learning","mlops","cloud","sdk"],"install":[{"cmd":"pip install azure-ai-ml","lang":"bash","label":"Install core library"},{"cmd":"pip install azure-ai-ml azure-identity","lang":"bash","label":"Install with authentication"}],"dependencies":[{"reason":"Required for authentication with Azure services, especially for `DefaultAzureCredential`.","package":"azure-identity","optional":false}],"imports":[{"note":"MLClient is the entry point for the v2 SDK, replacing Workspace from the v1 SDK (azureml-sdk).","wrong":"from azureml.core import Workspace","symbol":"MLClient","correct":"from azure.ai.ml import MLClient"},{"note":"Authentication credentials are provided by the separate azure-identity library.","wrong":"from azure.ai.ml.identity import DefaultAzureCredential","symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"},{"note":"Job-related entities and other assets are typically found under azure.ai.ml.entities.","wrong":"from azure.ai.ml import command","symbol":"CommandJob","correct":"from azure.ai.ml.entities import CommandJob"},{"note":"Similar to jobs, resource definitions like Environment are under azure.ai.ml.entities.","symbol":"Environment","correct":"from azure.ai.ml.entities import Environment"}],"quickstart":{"code":"import os\nfrom azure.ai.ml import MLClient\nfrom azure.identity import DefaultAzureCredential\n\n# Configure Azure credentials and workspace details\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID')\nresource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP')\nworkspace_name = os.environ.get('AZURE_ML_WORKSPACE_NAME', 'YOUR_WORKSPACE_NAME')\n\n# Instantiate DefaultAzureCredential\ntry:\n    credential = DefaultAzureCredential()\n    # Check if credential works by getting a token (optional, but good for early validation)\n    _ = credential.get_token('https://management.azure.com/.default')\nexcept Exception as e:\n    print(f\"Authentication failed: {e}\")\n    print(\"Please ensure you are logged in to Azure CLI, VS Code, or have appropriate environment variables set.\")\n    exit(1)\n\n# Create an MLClient instance\nml_client = MLClient(\n    credential=credential,\n    subscription_id=subscription_id,\n    resource_group_name=resource_group,\n    workspace_name=workspace_name\n)\n\nprint(f\"Connected to Azure ML workspace: {ml_client.workspace_name}\")\n\n# Example: List existing environments in the workspace\nprint(\"Listing existing environments...\")\nenvironments = ml_client.environments.list()\nfor env in environments:\n    print(f\"- {env.name} (version: {env.version})\")\n","lang":"python","description":"This quickstart demonstrates how to connect to an Azure Machine Learning workspace using the `MLClient` and `DefaultAzureCredential`. It retrieves workspace details from environment variables (or placeholders) and then lists the custom environments registered in the workspace. Ensure `AZURE_SUBSCRIPTION_ID`, `AZURE_RESOURCE_GROUP`, and `AZURE_ML_WORKSPACE_NAME` environment variables are set, or replace placeholders with your actual values. Also, authenticate via Azure CLI (`az login`) or other methods for `DefaultAzureCredential` to work."},"warnings":[{"fix":"Rewrite code to use the new v2 SDK paradigms. Refer to the official Azure ML v1 to v2 migration guide.","message":"Migration from Azure ML SDK v1 (`azureml-sdk`) to v2 (`azure-ai-ml`) involves significant breaking changes. The API surface is largely different, with new classes and methods for defining resources and submitting jobs. Projects built on v1 are not directly compatible with v2.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Verify Azure CLI login (`az account show`), check permissions for your user/service principal on the ML workspace, and ensure required environment variables are correctly configured for programmatic access.","message":"Authentication issues are common. `DefaultAzureCredential` attempts multiple authentication flows (e.g., Azure CLI, Managed Identity, Environment Variables, VS Code). If it fails, ensure you are logged in via `az login` or have relevant environment variables (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) correctly set.","severity":"gotcha","affected_versions":"All"},{"fix":"Always refer to the latest Azure ML documentation for the correct YAML schema. Use `ml_client.jobs.validate()` (or similar for other entities) to proactively check your YAML definitions before submission. Ensure correct indentation and field names.","message":"YAML schema for defining Azure ML resources (jobs, components, environments) can be strict and evolve. Subtle errors in YAML structure or parameter names can lead to validation failures or unexpected behavior.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}