Azure Machine Learning Core SDK (v1)
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
- breaking The `azureml-core` package (Python SDK v1) is deprecated. Support for it will end on June 30, 2026. Microsoft recommends migrating to the new Azure Machine Learning Python SDK v2 (`azure-ai-ml`) before this date to ensure continued support and access to new features.
- gotcha The Python SDK v1 (`azureml-core`) and Python SDK v2 (`azure-ai-ml`) are incompatible and should not be installed in the same environment, as this can cause clashes and confusion.
- breaking Python 3.7 reached end-of-life in June 2023. Support for Python 3.7 in `azureml-core` ended in February 2024. Python 3.6 support was deprecated earlier.
- deprecated The `Image` class in `azureml.core` for deploying web service endpoints is deprecated.
- gotcha Managing complex Python package dependencies within `Environment` objects can lead to long image build times and potential version conflicts.
- gotcha Hardcoding credentials or relying solely on interactive login for automated workflows can lead to security risks and operational issues.
- gotcha Dependency version mismatches between the pipeline runtime's `azureml-core` version and the expected SDK versions for pipeline components can cause `Failed to load entrypoint` errors in Azure ML Designer or pipelines.
Install
-
pip install azureml-core
Imports
- Workspace
from azureml.core import Workspace
- Environment
from azureml.core import Environment
- Model
from azureml.core import Model
- Image
from azureml.core import Image
Quickstart
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}")