Registry / azure / azure-ai-ml

azure-ai-ml

JSON →
library1.34.1pypypi✓ verified 24d ago

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.

pip install azure-ai-ml
INSTALL
IMPORT
SIG · AZURE-AI-ML
A
azure-ai-ml
azurepythonv1.34.1
Install
16.6s avg
Import
9454ms
Disk
244MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.34.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 9.851s · 228.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 16.6s · import 9.056s · 230MB
244MB installed
● package 244MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MLClient
from azure.ai.ml import MLClient
from azureml.core import Workspace
MLClient is the entry point for the v2 SDK, replacing Workspace from the v1 SDK (azureml-sdk).
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from azure.ai.ml.identity import DefaultAzureCredential
Authentication credentials are provided by the separate azure-identity library.
CommandJob
from azure.ai.ml.entities import CommandJob
from azure.ai.ml import command
Job-related entities and other assets are typically found under azure.ai.ml.entities.
Environment
from azure.ai.ml.entities import Environment
Similar to jobs, resource definitions like Environment are under azure.ai.ml.entities.

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.

import os from azure.ai.ml import MLClient from azure.identity import DefaultAzureCredential # Configure Azure credentials and workspace details subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'YOUR_SUBSCRIPTION_ID') resource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'YOUR_RESOURCE_GROUP') workspace_name = os.environ.get('AZURE_ML_WORKSPACE_NAME', 'YOUR_WORKSPACE_NAME') # Instantiate DefaultAzureCredential try: credential = DefaultAzureCredential() # Check if credential works by getting a token (optional, but good for early validation) _ = credential.get_token('https://management.azure.com/.default') except Exception as e: print(f"Authentication failed: {e}") print("Please ensure you are logged in to Azure CLI, VS Code, or have appropriate environment variables set.") exit(1) # Create an MLClient instance ml_client = MLClient( credential=credential, subscription_id=subscription_id, resource_group_name=resource_group, workspace_name=workspace_name ) print(f"Connected to Azure ML workspace: {ml_client.workspace_name}") # Example: List existing environments in the workspace print("Listing existing environments...") environments = ml_client.environments.list() for env in environments: print(f"- {env.name} (version: {env.version})")
az --version
Debug
Known issues
breakingMigration 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.
fix
Rewrite code to use the new v2 SDK paradigms. Refer to the official Azure ML v1 to v2 migration guide.
affects: <1.0.0
gotchaAuthentication 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.
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.
affects: All
gotchaYAML 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.
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.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.ai.ml'
The 'azure-ai-ml' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install azure-ai-ml'.
ImportError: cannot import name 'MLClient' from 'azure.ai.ml'
The 'azure-ai-ml' package is not installed or is outdated.
fix
Ensure the package is installed and up to date: 'pip install --upgrade azure-ai-ml'.
ImportError: cannot import name 'TokenCredential' from 'azure.core.credentials'
The 'azure-core' package is outdated and lacks the 'TokenCredential' class.
fix
Upgrade the 'azure-core' package: 'pip install --upgrade azure-core'.
ImportError: cannot import name 'INSTRUMENTATION_KEY' from 'azure.ai.ml._telemetry.logging_handler'
The 'INSTRUMENTATION_KEY' attribute has been removed or renamed in recent versions of 'azure-ai-ml'.
fix
Update the code to remove or replace references to 'INSTRUMENTATION_KEY'.
ImportError: cannot import name 'PromptAgentDefinition' from 'azure.ai.projects.models'
The 'PromptAgentDefinition' class is not present in the installed version of 'azure-ai-projects'.
fix
Verify the documentation for the correct import or update the package to the latest version.
Upgrade
Version history
1.34.1latest on PyPI · released Jul 14, 2026
Audit
Dependencies
azure-identityrequiredRequired for authentication with Azure services, especially for `DefaultAzureCredential`.
Agent activity
45 hits · last 30 days
node
38
OpenAI (training)
1
Resources
azure-ai-ml — pip install azure-ai-ml · libregistry