Environment
Base class for execution environments, shared by TaskEnvironment and AppEnvironment. Defines common infrastructure settings such as container image, compute resources, secrets, and deployment dependencies.
Attributes
| Attribute | Type | Description |
|---|---|---|
| name | str | Name of the environment (required). Must be snake_case or kebab-case. |
| depends_on | List[[Environment](environment.md?sid=flyte__environment_environment)] = [] | List of other environments to deploy alongside this one. |
| pod_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = None | Kubernetes pod template as a string reference to a named template or a PodTemplate object. |
| description | Optional[str] = None | Human-readable description (max 255 characters). |
| secrets | Optional[SecretRequest] = None | Secrets to inject into the environment. |
| env_vars | Optional[Dict[str, str]] = None | Environment variables as dict[str, str]. |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None | Compute resources (CPU, memory, GPU, disk) via a Resources object. |
| interruptible | bool = False | Whether the environment can be scheduled on spot/preemptible instances. |
| image | Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"], None] = "auto" | Docker image for the environment. Can be a string (image URI), an Image object, or "auto" to use the default image. |
| include | Tuple[str, ...] = () | Extra files to bundle with the environment's code (e.g., HTML templates, config files, non-Python assets). Paths may be relative (resolved against the directory of the file where the environment is instantiated), absolute, directories (recursively included), or glob patterns. Files listed here are bundled in addition to the default copy_style discovery (loaded_modules or all), not in place of it. |
Constructor
Signature
def Environment(
name: str,
image: Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"], None] = "auto",
resources: Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None,
env_vars: Optional[Dict[str, str]] = None,
secrets: Optional[SecretRequest] = None,
pod_template: Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = None,
description: Optional[str] = None,
interruptible: bool = False,
depends_on: List[[Environment](environment.md?sid=flyte__environment_environment)] = field(default_factory=list),
include: Tuple[str, ...] = field(default_factory=tuple)
)
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | Name of the environment (required). Must be snake_case or kebab-case. |
| image | Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"], None] = "auto" | Docker image for the environment. Can be a string (image URI), an Image object, or "auto" to use the default image. |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None | Compute resources (CPU, memory, GPU, disk) via a Resources object. |
| env_vars | Optional[Dict[str, str]] = None | Environment variables as dict[str, str]. |
| secrets | Optional[SecretRequest] = None | Secrets to inject into the environment. |
| pod_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = None | Kubernetes pod template as a string reference to a named template or a PodTemplate object. |
| description | Optional[str] = None | Human-readable description (max 255 characters). |
| interruptible | bool = False | Whether the environment can be scheduled on spot/preemptible instances. |
| depends_on | List[[Environment](environment.md?sid=flyte__environment_environment)] = field(default_factory=list) | List of other environments to deploy alongside this one. |
| include | Tuple[str, ...] = field(default_factory=tuple) | Extra files to bundle with the environment's code (e.g., HTML templates, config files, non-Python assets). Paths may be relative (resolved against the directory of the file where the environment is instantiated), absolute, directories (recursively included), or glob patterns. Files listed here are bundled in addition to the default copy_style discovery (loaded_modules or all), not in place of it. |
Methods
add_dependency()
@classmethod
def add_dependency(
env: [Environment](environment.md?sid=flyte__environment_environment)
)
Add one or more environment dependencies so they are deployed together. When you deploy this environment, any environments added via add_dependency will also be deployed. This is an alternative to passing depends_on=[...] at construction time, useful when the dependency is defined after the environment is created. Duplicate dependencies are silently ignored. An environment cannot depend on itself.
Parameters
| Name | Type | Description |
|---|---|---|
| env | [Environment](environment.md?sid=flyte__environment_environment) | One or more Environment instances to add as dependencies. |
clone_with()
@classmethod
def clone_with(
name: str,
image: Optional[Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]]] = None,
resources: Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None,
env_vars: Optional[Dict[str, str]] = None,
secrets: Optional[SecretRequest] = None,
depends_on: Optional[List[[Environment](environment.md?sid=flyte__environment_environment)]] = None,
description: Optional[str] = None,
kwargs: Any
) - > [Environment](environment.md?sid=flyte__environment_environment)
Creates a new Environment instance by cloning the current one and overriding specified attributes. This method is not yet implemented and will raise a NotImplementedError.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The name for the new cloned environment. |
| image | Optional[Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]]] = None | The Docker image for the new environment. Can be a string (image URI), an Image object, or "auto". |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None | The compute resources (CPU, memory, GPU, disk) for the new environment. |
| env_vars | Optional[Dict[str, str]] = None | The environment variables as a dictionary for the new environment. |
| secrets | Optional[SecretRequest] = None | The secrets to inject into the new environment. |
| depends_on | Optional[List[[Environment](environment.md?sid=flyte__environment_environment)]] = None | A list of other environments that the new environment depends on. |
| description | Optional[str] = None | A human-readable description for the new environment. |
| kwargs | Any | Additional keyword arguments to pass to the new environment's constructor. |
Returns
| Type | Description |
|---|---|
[Environment](environment.md?sid=flyte__environment_environment) | A new Environment instance with the specified attributes overridden. |