EnvironmentOperations Class

EnvironmentOperations.

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
EnvironmentOperations

Constructor

EnvironmentOperations(operation_scope: OperationScope, operation_config: OperationConfig, service_client: AzureMachineLearningWorkspaces | AzureMachineLearningWorkspaces, all_operations: OperationsContainer, **kwargs: Any)

Parameters

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

Scope variables for the operations classes of an MLClient object.

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

Common configuration for operations classes of an MLClient object.

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

Service client to allow end users to operate on Azure Machine Learning Workspace resources (ServiceClient042023Preview or ServiceClient102021Dataplane).

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

All operations classes of an MLClient object.

Methods

archive

Archive an environment or an environment version.

create_or_update

Returns created or updated environment asset.

get

Returns the specified environment asset.

list

List all environment assets in workspace.

restore

Restore an archived environment version.

share

Note

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

Share a environment asset from workspace to registry.

archive

Archive an environment or an environment version.

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

Parameters

Name Description
name
Required
str

Name of the environment.

version
Required
str

Version of the environment.

label
Required
str

Label of the environment. (mutually exclusive with version)

Examples

Archive example.


   ml_client.environments.archive("create-environment", "2.0")

create_or_update

Returns created or updated environment asset.

create_or_update(environment: Environment) -> Environment

Parameters

Name Description
environment
Required
<xref:azure.ai.ml.entities._assets.Environment>

Environment object

Returns

Type Description

Created or updated Environment object

Exceptions

Type Description

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

Raised if local path provided points to an empty directory.

Examples

Create environment.


   from azure.ai.ml.entities import BuildContext, Environment

   env_docker_context = Environment(
       build=BuildContext(
           path="./sdk/ml/azure-ai-ml/tests/test_configs/environment/environment_files",
           dockerfile_path="DockerfileNonDefault",
       ),
       name="create-environment",
       version="2.0",
       description="Environment created from a Docker context.",
   )
   ml_client.environments.create_or_update(env_docker_context)

get

Returns the specified environment asset.

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

Parameters

Name Description
name
Required
str

Name of the environment.

version
Required
str

Version of the environment.

label
Required
str

Label of the environment. (mutually exclusive with version)

Returns

Type Description

Environment object

Exceptions

Type Description

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

Examples

Get example.


   ml_client.environments.get("create-environment", "2.0")

list

List all environment assets in workspace.

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

Parameters

Name Description
name
Required

Name of the environment.

Keyword-Only Parameters

Name Description
list_view_type

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

Returns

Type Description

An iterator like instance of Environment objects.

Examples

List example.


   ml_client.environments.list()

restore

Restore an archived environment version.

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

Parameters

Name Description
name
Required
str

Name of the environment.

version
Required
str

Version of the environment.

label
Required
str

Label of the environment. (mutually exclusive with version)

Examples

Restore example.


   ml_client.environments.restore("create-environment", "2.0")

share

Note

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

Share a environment asset from workspace to registry.

share(name: str, version: str, *, share_with_name: str, share_with_version: str, registry_name: str) -> Environment

Parameters

Name Description
name
Required
str

Name of environment asset.

version
Required
str

Version of environment asset.

Keyword-Only Parameters

Name Description
share_with_name
str

Name of environment asset to share with.

share_with_version
str

Version of environment asset to share with.

registry_name
str

Name of the destination registry.

Returns

Type Description

Environment asset object.