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)]] = null | Kubernetes pod template as a string reference to a named template or a PodTemplate object. |
| description | Optional[str] = null | Human-readable description (max 255 characters). |
| secrets | Optional[SecretRequest] = null | Secrets to inject into the environment. |
| env_vars | Optional[Dict[str, str]] = null | Environment variables as dict[str, str]. |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = null | 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). |
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)] = [],
include: Tuple[str, ...] = ()
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | Name of the environment. Must be in snake_case or kebab-case format. |
| image | Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal['auto'], None] = "auto" | Docker image for the environment. Can be a URI string, an Image object, or 'auto' for the default image. |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = None | Compute resources such as CPU, memory, GPU, and disk requirements. |
| env_vars | Optional[Dict[str, str]] = None | A dictionary of environment variables to be set in the execution environment. |
| secrets | Optional[SecretRequest] = None | Secrets to be injected into the environment. |
| pod_template | Optional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = None | Kubernetes pod template reference or object. |
| description | Optional[str] = None | A human-readable description of the environment, capped at 255 characters. |
| interruptible | bool = False | Whether the environment can run on spot or preemptible instances. |
| depends_on | List[[Environment](environment.md?sid=flyte__environment_environment)] = [] | A list of other Environment instances that should be deployed alongside this one. |
| include | Tuple[str, ...] = () | Extra files or directories to bundle with the environment's code. |
Methods
add_dependency()
@classmethod
def add_dependency(
*env: [Environment](environment.md?sid=flyte__environment_environment)
) - > null
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. |
Returns
| Type | Description |
|---|---|
null |
clone_with()
@classmethod
def clone_with(
name: str,
image: Optional[Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]]],
resources: Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)],
env_vars: Optional[Dict[str, str]],
secrets: Optional[SecretRequest],
depends_on: Optional[List[[Environment](environment.md?sid=flyte__environment_environment)]],
description: Optional[str],
**kwargs: Any
) - > [Environment](environment.md?sid=flyte__environment_environment)
Creates a new instance of the environment with updated configuration values. This method is intended to be overridden by subclasses to support creating variations of existing environments.
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The unique name for the new cloned environment. |
| image | Optional[Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]]] | The Docker image URI or Image object to use for the new environment. |
| resources | Optional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] | The compute resource requirements (CPU, Memory, GPU) for the new environment. |
| env_vars | Optional[Dict[str, str]] | A dictionary of environment variables to be set in the execution context. |
| secrets | Optional[SecretRequest] | The secret requests defining sensitive data to be injected into the environment. |
| depends_on | Optional[List[[Environment](environment.md?sid=flyte__environment_environment)]] | A list of other Environment instances that must be deployed alongside this one. |
| description | Optional[str] | A human-readable summary of the environment's purpose. |
| **kwargs | Any | Additional implementation-specific arguments for the cloned environment. |
Returns
| Type | Description |
|---|---|
[Environment](environment.md?sid=flyte__environment_environment) | A new Environment instance with the specified overrides applied. |