Skip to main content

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

AttributeTypeDescription
namestrName of the environment (required). Must be snake_case or kebab-case.
depends_onList[[Environment](environment.md?sid=flyte__environment_environment)] = []List of other environments to deploy alongside this one.
pod_templateOptional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = NoneKubernetes pod template as a string reference to a named template or a PodTemplate object.
descriptionOptional[str] = NoneHuman-readable description (max 255 characters).
secretsOptional[SecretRequest] = NoneSecrets to inject into the environment.
env_varsOptional[Dict[str, str]] = NoneEnvironment variables as dict[str, str].
resourcesOptional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = NoneCompute resources (CPU, memory, GPU, disk) via a Resources object.
interruptiblebool = FalseWhether the environment can be scheduled on spot/preemptible instances.
imageUnion[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.
includeTuple[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

NameTypeDescription
namestrName of the environment (required). Must be snake_case or kebab-case.
imageUnion[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.
resourcesOptional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = NoneCompute resources (CPU, memory, GPU, disk) via a Resources object.
env_varsOptional[Dict[str, str]] = NoneEnvironment variables as dict[str, str].
secretsOptional[SecretRequest] = NoneSecrets to inject into the environment.
pod_templateOptional[Union[str, [PodTemplate](../pod/podtemplate.md?sid=flyte__pod_podtemplate)]] = NoneKubernetes pod template as a string reference to a named template or a PodTemplate object.
descriptionOptional[str] = NoneHuman-readable description (max 255 characters).
interruptiblebool = FalseWhether the environment can be scheduled on spot/preemptible instances.
depends_onList[[Environment](environment.md?sid=flyte__environment_environment)] = field(default_factory=list)List of other environments to deploy alongside this one.
includeTuple[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

NameTypeDescription
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

NameTypeDescription
namestrThe name for the new cloned environment.
imageOptional[Union[str, [Image](../image/image.md?sid=flyte__image_image), Literal["auto"]]] = NoneThe Docker image for the new environment. Can be a string (image URI), an Image object, or "auto".
resourcesOptional[[Resources](../resources/resources.md?sid=flyte__resources_resources)] = NoneThe compute resources (CPU, memory, GPU, disk) for the new environment.
env_varsOptional[Dict[str, str]] = NoneThe environment variables as a dictionary for the new environment.
secretsOptional[SecretRequest] = NoneThe secrets to inject into the new environment.
depends_onOptional[List[[Environment](environment.md?sid=flyte__environment_environment)]] = NoneA list of other environments that the new environment depends on.
descriptionOptional[str] = NoneA human-readable description for the new environment.
kwargsAnyAdditional keyword arguments to pass to the new environment's constructor.

Returns

TypeDescription
[Environment](environment.md?sid=flyte__environment_environment)A new Environment instance with the specified attributes overridden.