ComponentOperations Class

ComponentOperations.

You should not instantiate this class directly. Instead, you should create an MLClient instance that instantiates it for you and attaches it as an attribute.

Inheritance
azure.ai.ml._scope_dependent_operations._ScopeDependentOperations
ComponentOperations

Constructor

ComponentOperations(operation_scope: OperationScope, operation_config: OperationConfig, service_client: AzureMachineLearningWorkspaces | AzureMachineLearningWorkspaces, all_operations: OperationsContainer, preflight_operation: DeploymentsOperations | None = None, **kwargs: Dict)

Parameters

Name Description
operation_scope
Required
<xref:azure.ai.ml._scope_dependent_operations.OperationScope>

The operation scope.

operation_config
Required
<xref:azure.ai.ml._scope_dependent_operations.OperationConfig>

The operation configuration.

service_client
Required
Union[ <xref:azure.ai.ml._restclient.v2022_10_01.AzureMachineLearningWorkspaces>, <xref:azure.ai.ml._restclient.v2021_10_01_dataplanepreview.AzureMachineLearningWorkspaces>]

The service client for API operations.

all_operations
Required
<xref:azure.ai.ml._scope_dependent_operations.OperationsContainer>

The container for all available operations.

preflight_operation
Optional[<xref:azure.ai.ml._vendor.azure_resources.operations.DeploymentsOperations>]

The preflight operation for deployments.

Default value: None
kwargs
Required

Additional keyword arguments.

Methods

archive

Archive a component.

create_or_update

Create or update a specified component. if there're inline defined entities, e.g. Environment, Code, they'll be created together with the component.

download

Note

This is an experimental method, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.

Download the specified component and its dependencies to local. Local component can be used to create the component in another workspace or for offline development.

get

Returns information about the specified component.

list

List specific component or components of the workspace.

restore

Restore an archived component.

validate

Note

This is an experimental method, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.

validate a specified component. if there are inline defined entities, e.g. Environment, Code, they won't be created.

archive

Archive a component.

archive(name: str, version: str | None = None, label: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
name
Required
str

Name of the component.

version
Required
str

Version of the component.

label
Required
str

Label of the component. (mutually exclusive with version).

Examples

Archive component example.


   ml_client.components.archive(name=component_example.name)

create_or_update

Create or update a specified component. if there're inline defined entities, e.g. Environment, Code, they'll be created together with the component.

create_or_update(component: Component, version: str | None = None, *, skip_validation: bool = False, **kwargs: Any) -> Component

Parameters

Name Description
component
Required

The component object or a mldesigner component function that generates component object

version
Required
str

The component version to override.

Keyword-Only Parameters

Name Description
skip_validation

whether to skip validation before creating/updating the component, defaults to False

Returns

Type Description

The specified component object.

Exceptions

Type Description

Raised if Component cannot be successfully validated. Details will be provided in the error message.

Raised if Component assets (e.g. Data, Code, Model, Environment) cannot be successfully validated. Details will be provided in the error message.

Raised if Component type is unsupported. Details will be provided in the error message.

Raised if Component model cannot be successfully validated. Details will be provided in the error message.

Raised if local path provided points to an empty directory.

Examples

Create component example.


   from azure.ai.ml import load_component
   from azure.ai.ml.entities._component.component import Component

   component_example = load_component(
       source="./sdk/ml/azure-ai-ml/tests/test_configs/components/helloworld_component.yml",
       params_override=[{"version": "1.0.2"}],
   )
   component = ml_client.components.create_or_update(component_example)

download

Note

This is an experimental method, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.

Download the specified component and its dependencies to local. Local component can be used to create the component in another workspace or for offline development.

download(name: str, download_path: PathLike | str = '.', *, version: str | None = None) -> None

Parameters

Name Description
name
Required
str

Name of the code component.

download_path
Required
str

Local path as download destination, defaults to current working directory of the current user. Will be created if not exists.

Keyword-Only Parameters

Name Description
version

Version of the component.

Returns

Type Description

The specified component object.

Exceptions

Type Description

Raised if download_path is pointing to an existing directory that is not empty. identified and retrieved. Details will be provided in the error message.

get

Returns information about the specified component.

get(name: str, version: str | None = None, label: str | None = None) -> Component

Parameters

Name Description
name
Required
str

Name of the code component.

version
Required

Version of the component.

label
Required

Label of the component, mutually exclusive with version.

Returns

Type Description

The specified component object.

Exceptions

Type Description

Raised if Component cannot be successfully identified and retrieved. Details will be provided in the error message.

Examples

Get component example.


   ml_client.components.get(name=component_example.name, version="1.0.2")

list

List specific component or components of the workspace.

list(name: str | None = None, *, list_view_type: ListViewType = ListViewType.ACTIVE_ONLY) -> Iterable[Component]

Parameters

Name Description
name
Required

Component name, if not set, list all components of the workspace

Keyword-Only Parameters

Name Description
list_view_type

View type for including/excluding (for example) archived components. Default: ACTIVE_ONLY.

Returns

Type Description

An iterator like instance of component objects

Examples

List component example.


   print(ml_client.components.list())

restore

Restore an archived component.

restore(name: str, version: str | None = None, label: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
name
Required
str

Name of the component.

version
Required
str

Version of the component.

label
Required
str

Label of the component. (mutually exclusive with version).

Examples

Restore component example.


   ml_client.components.restore(name=component_example.name)

validate

Note

This is an experimental method, and may change at any time. Please see https://aka.ms/azuremlexperimental for more information.

validate a specified component. if there are inline defined entities, e.g. Environment, Code, they won't be created.

validate(component: Component | function, raise_on_failure: bool = False, **kwargs: Any) -> ValidationResult

Parameters

Name Description
component
Required

The component object or a mldesigner component function that generates component object

raise_on_failure
Required

Whether to raise exception on validation error. Defaults to False

Returns

Type Description

All validation errors