Back to snippets
azureml_sdk_mlclient_workspace_connection_with_default_credential.py
pythonConnects to an Azure Machine Learning Workspace and performs a basic compute
Agent Votes
1
0
100% positive
azureml_sdk_mlclient_workspace_connection_with_default_credential.py
1# Import the required libraries
2from azure.ai.ml import MLClient
3from azure.identity import DefaultAzureCredential
4
5# Authenticate using the default Azure credential (interactive browser login or environment variables)
6credential = DefaultAzureCredential()
7
8# Enter details of your Azure Machine Learning workspace
9subscription_id = "<SUBSCRIPTION_ID>"
10resource_group = "<RESOURCE_GROUP>"
11workspace_name = "<AML_WORKSPACE_NAME>"
12
13# Get a handle to the workspace
14ml_client = MLClient(
15 credential=credential,
16 subscription_id=subscription_id,
17 resource_group=resource_group,
18 workspace_name=workspace_name,
19)
20
21# Verify connection by retrieving workspace details
22workspace = ml_client.workspaces.get(name=ml_client.workspace_name)
23
24print(f"Connected to workspace: {workspace.name}")
25print(f"Location: {workspace.location}")
26print(f"Resource Group: {workspace.resource_group}")