MLClient Class

A client class to interact with Azure ML services.

Use this client to manage Azure ML resources such as workspaces, jobs, models, and so on.

Inheritance
builtins.object
MLClient

Constructor

MLClient(credential: TokenCredential, subscription_id: str | None = None, resource_group_name: str | None = None, workspace_name: str | None = None, registry_name: str | None = None, **kwargs: Any)

Parameters

Name Description
credential
Required

The credential to use for authentication.

subscription_id

The Azure subscription ID. Optional for registry assets only. Defaults to None.

default value: None
resource_group_name

The Azure resource group. Optional for registry assets only. Defaults to None.

default value: None
workspace_name

The workspace to use in the client. Optional only for operations that are not workspace-dependent. Defaults to None.

default value: None
registry_name

The registry to use in the client. Optional only for operations that are not workspace-dependent. Defaults to None.

default value: None

Keyword-Only Parameters

Name Description
show_progress

Specifies whether or not to display progress bars for long-running operations (e.g. customers may consider setting this to False if not using this SDK in an interactive setup). Defaults to True.

enable_telemetry

Specifies whether or not to enable telemetry. Will be overridden to False if not in a Jupyter Notebook. Defaults to True if in a Jupyter Notebook.

cloud

The cloud name to use. Defaults to "AzureCloud".

Examples

When using sovereign domains (i.e. any cloud other than AZURE_PUBLIC_CLOUD), you must pass in the cloud name in kwargs and you must use an authority with DefaultAzureCredential.


   from azure.ai.ml import MLClient
   from azure.identity import AzureAuthorityHosts, DefaultAzureCredential

   kwargs = {"cloud": "AzureChinaCloud"}
   ml_client = MLClient(
       subscription_id=subscription_id,
       resource_group_name=resource_group,
       credential=DefaultAzureCredential(authority=AzureAuthorityHosts.AZURE_CHINA),
       **kwargs,
   )

Methods

begin_create_or_update

Creates or updates an Azure ML resource asynchronously.

create_or_update

Creates or updates an Azure ML resource.

from_config

Returns a client from an existing Azure Machine Learning Workspace using a file configuration.

This method provides a simple way to reuse the same workspace across multiple Python notebooks or projects. You can save a workspace's Azure Resource Manager (ARM) properties in a JSON configuration file using this format:


   {
       "subscription_id": "<subscription-id>",
       "resource_group": "<resource-group>",
       "workspace_name": "<workspace-name>"
   }

Then, you can use this method to load the same workspace in different Python notebooks or projects without retyping the workspace ARM properties.

begin_create_or_update

Creates or updates an Azure ML resource asynchronously.

begin_create_or_update(entity: R, **kwargs) -> LROPoller[R]

Parameters

Name Description
entity
Required

The resource to create or update.

Returns

Type Description

The resource after create/update operation.

create_or_update

Creates or updates an Azure ML resource.

create_or_update(entity: T, **kwargs) -> T

Parameters

Name Description
entity
Required

The resource to create or update.

Returns

Type Description

The created or updated resource.

from_config

Returns a client from an existing Azure Machine Learning Workspace using a file configuration.

This method provides a simple way to reuse the same workspace across multiple Python notebooks or projects. You can save a workspace's Azure Resource Manager (ARM) properties in a JSON configuration file using this format:


   {
       "subscription_id": "<subscription-id>",
       "resource_group": "<resource-group>",
       "workspace_name": "<workspace-name>"
   }

Then, you can use this method to load the same workspace in different Python notebooks or projects without retyping the workspace ARM properties.

from_config(credential: TokenCredential, *, path: PathLike | str | None = None, file_name=None, **kwargs) -> MLClient

Parameters

Name Description
credential
Required

The credential object for the workspace.

Keyword-Only Parameters

Name Description
path

The path to the configuration file or starting directory to search for the configuration file within. Defaults to None, indicating the current directory will be used.

file_name

The configuration file name to search for when path is a directory path. Defaults to "config.json".

cloud

The cloud name to use. Defaults to "AzureCloud".

Returns

Type Description

The client for an existing Azure ML Workspace.

Exceptions

Type Description

Raised if "config.json", or file_name if overridden, cannot be found in directory. Details will be provided in the error message.

Examples

Creating an MLClient from a file named "config.json" in directory "src".


   from azure.ai.ml import MLClient

   client = MLClient.from_config(credential=DefaultAzureCredential(), path="./sdk/ml/azure-ai-ml/samples/src")

Creating an MLClient from a file named "team_workspace_configuration.json" in the current directory.


   from azure.ai.ml import MLClient

   client = MLClient.from_config(
       credential=DefaultAzureCredential(),
       file_name="./sdk/ml/azure-ai-ml/samples/team_workspace_configuration.json",
   )

Attributes

batch_deployments

A collection of batch deployment related operations.

Returns

Type Description

Batch Deployment operations.

batch_endpoints

A collection of batch endpoint related operations.

Returns

Type Description

Batch Endpoint operations

components

A collection of component related operations.

Returns

Type Description

Component operations.

compute

A collection of compute related operations.

Returns

Type Description

Compute operations

connections

A collection of workspace connection related operations.

Returns

Type Description

Workspace Connections operations

data

A collection of data related operations.

Returns

Type Description

Data operations.

datastores

A collection of datastore related operations.

Returns

Type Description

Datastore operations.

environments

A collection of environment related operations.

Returns

Type Description

Environment operations.

feature_sets

A collection of feature set related operations.

Returns

Type Description

FeatureSet operations

feature_store_entities

A collection of feature store entity related operations.

Returns

Type Description

FeatureStoreEntity operations

feature_stores

A collection of feature store related operations.

Returns

Type Description

FeatureStore operations

jobs

A collection of job related operations.

Returns

Type Description

Job operations

models

A collection of model related operations.

Returns

Type Description

Model operations

online_deployments

A collection of online deployment related operations.

Returns

Type Description

Online Deployment operations

online_endpoints

A collection of online endpoint related operations.

Returns

Type Description

Online Endpoint operations

registries

A collection of registry-related operations.

Returns

Type Description

Registry operations

resource_group_name

Get the resource group name of an MLClient object.

Returns

Type Description
str

An Azure resource group name.

schedules

A collection of schedule related operations.

Returns

Type Description

Schedule operations.

subscription_id

Get the subscription ID of an MLClient object.

Returns

Type Description
str

An Azure subscription ID.

workspace_hubs

//aka.ms/azuremlexperimental for more information.

A collection of workspace hub-related operations.

Returns

Type Description
<xref:HubOperations>

Hub Operations

workspace_name

The name of the workspace where workspace-dependent operations will be executed.

Returns

Type Description

The name of the default workspace.

workspace_outbound_rules

A collection of workspace outbound rule related operations.

Returns

Type Description

Workspace outbound rule operations

workspaces

A collection of workspace-related operations.

Returns

Type Description

Workspace operations

R

R = ~R

T

T = ~T