Environment Class

Environment for training.

Inheritance
azure.ai.ml.entities._assets.asset.Asset
Environment
azure.ai.ml.entities._mixins.LocalizableMixin
Environment

Constructor

Environment(*, name: str | None = None, version: str | None = None, description: str | None = None, image: str | None = None, build: BuildContext | None = None, conda_file: str | PathLike | Dict | None = None, tags: Dict | None = None, properties: Dict | None = None, datastore: str | None = None, **kwargs: Any)

Parameters

Name Description
name
Required
str

Name of the resource.

version
Required
str

Version of the asset.

description
Required
str

Description of the resource.

image
Required
str

URI of a custom base image.

build
Required

Docker build context to create the environment. Mutually exclusive with "image"

conda_file
Required

Path to configuration file listing conda packages to install.

tags
Required

Tag dictionary. Tags can be added, removed, and updated.

properties
Required

The asset property dictionary.

datastore
Required
str

The datastore to upload the local artifact to.

kwargs
Required

A dictionary of additional configuration parameters.

Keyword-Only Parameters

Name Description
name
Required
version
Required
description
Required
image
Required
build
Required
conda_file
Required
tags
Required
properties
Required
datastore
Required

Examples

Create a Environment object.


   from azure.ai.ml.entities._assets.environment import Environment

   environment = Environment(
       name="env-name",
       version="2.0",
       description="env-description",
       image="env-image",
       conda_file="./sdk/ml/azure-ai-ml/tests/test_configs/deployments/model-1/environment/conda.yml",
       tags={"tag1": "value1", "tag2": "value2"},
       properties={"prop1": "value1", "prop2": "value2"},
       datastore="datastore",
   )

Methods

dump

Dump the asset content into a file in YAML format.

validate

Validate the environment by checking its name, image and build

dump

Dump the asset content into a file in YAML format.

dump(dest: str | PathLike | IO, **kwargs: Any) -> None

Parameters

Name Description
dest
Required
Union[<xref:PathLike>, str, IO[AnyStr]]

The local path or file stream to write the YAML content to. If dest is a file path, a new file will be created. If dest is an open file, the file will be written to directly.

Exceptions

Type Description

Raised if dest is a file path and the file already exists.

Raised if dest is an open file and the file is not writable.

validate

Validate the environment by checking its name, image and build

validate() -> None

Exceptions

Type Description

Raised if dest is a file path and the file already exists.

Raised if dest is an open file and the file is not writable.

Examples

Validate environment example.


   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.",
   )

   env_docker_context.validate()

Attributes

base_path

The base path of the resource.

Returns

Type Description
str

The base path of the resource.

conda_file

Conda environment specification.

Returns

Type Description

Conda dependencies loaded from conda_file param.

creation_context

The creation context of the resource.

Returns

Type Description

The creation metadata for the resource.

id

The resource ID.

Returns

Type Description

The global ID of the resource, an Azure Resource Manager (ARM) ID.

version

The asset version.

Returns

Type Description
str

The asset version.