Skip to main content

Image

Container image specification built using a fluent, two-step pattern:

  1. Create a base image with a from_* constructor
  2. Customize with with_* methods (each returns a new Image)

Attributes

AttributeTypeDescription
base_imageOptional[str] = nullThe base image URI from which this image is derived, if not built from a Dockerfile.
dockerfileOptional[Path] = nullThe path to a Dockerfile used to build this image, if applicable.
registryOptional[str] = nullThe container registry where this image will be stored or pulled from.
nameOptional[str] = nullThe name of the image within the registry.
platformTuple[Architecture, ...] = ("linux/amd64",)The target platform(s) for the image, such as 'linux/amd64' or 'linux/arm64'.
python_versionTuple[int, int] = _detect_python_versionThe Python version used in the image, represented as a tuple (major, minor).
extendablebool = falseA boolean indicating whether additional layers can be added to this image after its creation.

Methods


validate()

@classmethod
def validate() - > null

Validates all layers associated with the image. This ensures that each layer's configuration is correct before the image is built or used.

Returns

TypeDescription
nullThis method does not return any value.

from_debian_base()

@classmethod
def from_debian_base(
python_version: Optional[Tuple[int, int]] = None,
flyte_version: Optional[str] = None,
install_flyte: bool = True,
registry: Optional[str] = None,
registry_secret: Optional[str | Secret] = None,
name: Optional[str] = None,
platform: Optional[Tuple[Architecture, ...]] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance using a default Debian-based image with a specified Python version. This is a convenient constructor for starting with a standard, multi-architecture base image.

Parameters

NameTypeDescription
python_versionOptional[Tuple[int, int]] = NoneThe major and minor Python version (e.g., (3, 10)) to use. If None, the current Python version will be detected and used.
flyte_versionOptional[str] = NoneThe Flyte version to include in the image. If None, the current SDK version is used.
install_flytebool = TrueA boolean indicating whether to install the Flyte library in the image.
registryOptional[str] = NoneThe container registry where the image will be stored. If None, a default registry is used.
registry_secret`Optional[strSecret]` = None
nameOptional[str] = NoneA custom name for the image. If None, a default name is generated.
platformOptional[Tuple[Architecture, ...]] = NoneThe target platform(s) for the image, such as 'linux/amd64' or 'linux/arm64'. If None, defaults to multi-arch 'linux/amd64', 'linux/arm64'.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured with the specified Debian base.

from_base()

@classmethod
def from_base(
image_uri: str
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance from a pre-built base image specified by its full URI. This method is used when you want to start with an existing image that is already available in a registry.

Parameters

NameTypeDescription
image_uristrThe full URI of the base image, including registry, name, and tag (e.g., 'myregistry/myimage:mytag').

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured with the specified base image URI.

from_ref_name()

@classmethod
def from_ref_name(
name: str = _DEFAULT_IMAGE_REF_NAME
) - > [Image](image.md?sid=flyte__image_image)

Creates an Image instance by referencing a pre-built image using its name. This allows you to refer to images defined elsewhere (e.g., in CLI or configuration) and potentially add further layers.

Parameters

NameTypeDescription
namestr = _DEFAULT_IMAGE_REF_NAMEThe reference name of the pre-built image.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object referencing the specified image name.

from_uv_script()

@classmethod
def from_uv_script(
script: Path | str,
name: str,
registry: str | None = None,
registry_secret: Optional[str | Secret] = None,
python_version: Optional[Tuple[int, int]] = None,
index_url: Optional[str] = None,
extra_index_urls: Union[str, List[str], Tuple[str, ...], None] = None,
pre: bool = False,
extra_args: Optional[str] = None,
platform: Optional[Tuple[Architecture, ...]] = None,
secret_mounts: Optional[SecretRequest] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance by parsing a uv-compatible script to determine Python version and dependencies. This method is useful for building images where dependencies are declared directly within a script's header.

Parameters

NameTypeDescription
script`Pathstr`
namestrThe name of the image to be created.
registry`strNone` = None
registry_secret`Optional[strSecret]` = None
python_versionOptional[Tuple[int, int]] = NoneThe major and minor Python version (e.g., (3, 10)) to use. If None, the Python version specified in the script's header or the current Python version will be used.
index_urlOptional[str] = NoneThe base URL of the Python package index to use for dependency resolution.
extra_index_urlsUnion[str, List[str], Tuple[str, ...], None] = NoneAdditional URLs of Python package indexes to use for dependency resolution.
prebool = FalseA boolean indicating whether to allow pre-release versions of packages during installation.
extra_argsOptional[str] = NoneAdditional arguments to pass directly to the uv installation command.
platformOptional[Tuple[Architecture, ...]] = NoneThe target platform(s) for the image, such as 'linux/amd64' or 'linux/arm64'. If None, defaults to 'linux/amd64'.
secret_mountsOptional[SecretRequest] = NoneA list of secret requests to mount during the image build process, useful for accessing private package indexes.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured based on the uv script.

clone()

@classmethod
def clone(
registry: Optional[str] = None,
registry_secret: Optional[str | Secret] = None,
name: Optional[str] = None,
base_image: Optional[str] = None,
python_version: Optional[Tuple[int, int]] = None,
addl_layer: Optional[Layer] = None,
extendable: Optional[bool] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that is a copy of the current image, allowing for modifications to its base properties or the addition of new layers. This method is essential for the fluent API pattern, where each with_* method returns a new, modified Image.

Parameters

NameTypeDescription
registryOptional[str] = NoneThe container registry where the cloned image will be stored. If None, the original image's registry is retained.
registry_secret`Optional[strSecret]` = None
nameOptional[str] = NoneA custom name for the cloned image. If None, the original image's name is retained.
base_imageOptional[str] = NoneA new base image URI to use for the cloned image. If None, the original image's base image is retained.
python_versionOptional[Tuple[int, int]] = NoneThe major and minor Python version (e.g., (3, 10)) for the cloned image. If None, the original image's Python version is retained.
addl_layerOptional[Layer] = NoneAn additional layer to append to the cloned image's existing layers. This allows for incremental modifications.
extendableOptional[bool] = NoneA boolean indicating whether the cloned image can be further extended with additional layers. If None, the original image's extendable property is retained.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object, which is a deep copy of the original with specified modifications.

from_dockerfile()

@classmethod
def from_dockerfile(
file: Union[Path, str],
registry: str,
name: str,
platform: Union[Architecture, Tuple[Architecture, ...], None] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance from a custom Dockerfile. This method provides maximum flexibility for image definition but prevents further layering using with_* methods, as the system does not parse the Dockerfile's contents.

Parameters

NameTypeDescription
fileUnion[Path, str]The file path to the Dockerfile. It is recommended to use an absolute Path object.
registrystrThe container registry where the image will be stored.
namestrThe name of the image to be created.
platformUnion[Architecture, Tuple[Architecture, ...], None] = NoneThe target platform(s) for the image, such as 'linux/amd64' or 'linux/arm64'. If None, defaults to 'linux/amd64'.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured from the specified Dockerfile.

uri()

@classmethod
def uri() - > str

Constructs and returns the full URI of the image, combining the registry, name, and final tag. This URI uniquely identifies the image in a container registry.

Returns

TypeDescription
strA string representing the full URI of the image (e.g., 'myregistry/myimage:mytag').

with_workdir()

@classmethod
def with_workdir(
workdir: str
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance with a specified working directory. This method allows you to define the default directory where commands will be executed inside the container.

Parameters

NameTypeDescription
workdirstrThe working directory path to set inside the image.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified working directory configured.

with_requirements()

@classmethod
def with_requirements(
file: str | Path,
index_url: Optional[str] = None,
extra_index_urls: Union[str, List[str], Tuple[str, ...], None] = None,
pre: bool = False,
extra_args: Optional[str] = None,
secret_mounts: Optional[SecretRequest] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that includes Python packages specified in a requirements.txt file. This method is used to install dependencies from a standard Python requirements file.

Parameters

NameTypeDescription
file`strPath`
index_urlOptional[str] = NoneThe base URL of the Python package index to use for dependency resolution.
extra_index_urlsUnion[str, List[str], Tuple[str, ...], None] = NoneAdditional URLs of Python package indexes to use for dependency resolution.
prebool = FalseA boolean indicating whether to allow pre-release versions of packages during installation.
extra_argsOptional[str] = NoneAdditional arguments to pass directly to the pip install command.
secret_mountsOptional[SecretRequest] = NoneA list of secret requests to mount during the image build process, useful for accessing private package indexes.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified requirements installed.

with_pip_packages()

@classmethod
def with_pip_packages(
*packages: str,
index_url: Optional[str] = None,
extra_index_urls: Union[str, List[str], Tuple[str, ...], None] = None,
pre: bool = False,
extra_args: Optional[str] = None,
secret_mounts: Optional[SecretRequest] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance with specified Python packages installed using pip. This method allows for direct installation of individual Python packages and their versions.

Parameters

NameTypeDescription
*packagesstrA variable number of strings, each representing a pip package specification (e.g., 'requests', 'numpy==1.20.0').
index_urlOptional[str] = NoneThe base URL of the Python package index to use for dependency resolution.
extra_index_urlsUnion[str, List[str], Tuple[str, ...], None] = NoneAdditional URLs of Python package indexes to use for dependency resolution.
prebool = FalseA boolean indicating whether to allow pre-release versions of packages during installation.
extra_argsOptional[str] = NoneAdditional arguments to pass directly to the pip install command.
secret_mountsOptional[SecretRequest] = NoneA list of secret requests to mount during the image build process, useful for accessing private package indexes.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified pip packages installed.

with_env_vars()

@classmethod
def with_env_vars(
env_vars: Dict[str, str]
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance with specified environment variables set. This method allows you to configure environment-specific settings that will be available inside the container.

Parameters

NameTypeDescription
env_varsDict[str, str]A dictionary where keys are environment variable names and values are their corresponding string values.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified environment variables configured.

with_source_folder()

@classmethod
def with_source_folder(
src: Path,
dst: str = .,
copy_contents_only: bool = False
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that includes a local directory copied into the image. This method is used to add source code or other assets from your local filesystem to the container.

Parameters

NameTypeDescription
srcPathThe path to the local source folder to be copied. This path is relative to the build context.
dststr = .The destination path inside the image where the source folder will be copied. Defaults to the working directory.
copy_contents_onlybool = FalseA boolean indicating whether to copy only the contents of the source folder (True) or the folder itself (False) into the destination.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified source folder copied into it.

with_source_file()

@classmethod
def with_source_file(
src: typing.Union[Path, typing.List[Path]],
dst: str = .
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that includes one or more local files copied into the image. This method is used to add specific files from your local filesystem to the container.

Parameters

NameTypeDescription
srctyping.Union[Path, typing.List[Path]]The path to a single local file or a list of paths to local files to be copied. These paths are relative to the build context.
dststr = .The destination path inside the image where the source file(s) will be copied. Defaults to the working directory.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified source file(s) copied into it.

with_code_bundle()

@classmethod
def with_code_bundle(
copy_style: Literal["loaded_modules", "all"] = loaded_modules,
dst: str = .
) - > [Image](image.md?sid=flyte__image_image)

Configures the image to automatically copy source code from the root directory based on a specified copy style. This method helps ensure that necessary application code is present in the container for execution.

Parameters

NameTypeDescription
copy_styleLiteral["loaded_modules", "all"] = loaded_modulesThe strategy for copying code: 'loaded_modules' copies only imported Python modules, while 'all' copies all files from the root directory.
dststr = .The destination directory inside the container where the code bundle will be copied. Defaults to the working directory.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured to include the specified code bundle.

with_dockerignore()

@classmethod
def with_dockerignore(
path: Path
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that incorporates a .dockerignore file. This method allows you to specify patterns for files and directories that should be excluded from the build context when building the Docker image.

Parameters

NameTypeDescription
pathPathThe file path to the .dockerignore file.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured with the specified .dockerignore file.

with_uv_project()

@classmethod
def with_uv_project(
pyproject_file: str | Path,
uvlock: Path | None = None,
index_url: Optional[str] = None,
extra_index_urls: Union[List[str], Tuple[str, ...], None] = None,
pre: bool = False,
extra_args: Optional[str] = None,
secret_mounts: Optional[SecretRequest] = None,
project_install_mode: typing.Literal["dependencies_only", "install_project"] = dependencies_only
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that installs dependencies from a uv project, typically defined by pyproject.toml and uv.lock files. This method is used for projects managed with uv to ensure consistent dependency installation.

Parameters

NameTypeDescription
pyproject_file`strPath`
uvlock`PathNone` = None
index_urlOptional[str] = NoneThe base URL of the Python package index to use for dependency resolution.
extra_index_urlsUnion[List[str], Tuple[str, ...], None] = NoneAdditional URLs of Python package indexes to use for dependency resolution.
prebool = FalseA boolean indicating whether to allow pre-release versions of packages during installation.
extra_argsOptional[str] = NoneAdditional arguments to pass directly to the uv installation command.
secret_mountsOptional[SecretRequest] = NoneA list of secret requests to mount during the image build process, useful for accessing private package indexes.
project_install_modetyping.Literal["dependencies_only", "install_project"] = dependencies_onlyDetermines whether to install only the project's dependencies ('dependencies_only') or to also install the project itself as a package ('install_project').

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the uv project dependencies installed.

with_poetry_project()

@classmethod
def with_poetry_project(
pyproject_file: str | Path,
poetry_lock: Path | None = None,
extra_args: Optional[str] = None,
secret_mounts: Optional[SecretRequest] = None,
project_install_mode: typing.Literal["dependencies_only", "install_project"] = dependencies_only
) - > null

Creates a new Image instance that installs dependencies from a Poetry project, typically defined by pyproject.toml and poetry.lock files. This method is used for projects managed with Poetry to ensure consistent dependency installation.

Parameters

NameTypeDescription
pyproject_file`strPath`
poetry_lock`PathNone` = None
extra_argsOptional[str] = NoneAdditional arguments to pass directly to the Poetry installation command (e.g., --no-root to install only dependencies).
secret_mountsOptional[SecretRequest] = NoneA list of secret requests to mount during the image build process, useful for accessing private package indexes.
project_install_modetyping.Literal["dependencies_only", "install_project"] = dependencies_onlyDetermines whether to install only the project's dependencies ('dependencies_only') or to also install the project itself as a package ('install_project').

Returns

TypeDescription
nullThis method does not return any value.

with_apt_packages()

@classmethod
def with_apt_packages(
*packages: str,
secret_mounts: Optional[SecretRequest] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that installs specified APT packages. This method is used to add system-level dependencies that are available through the APT package manager on Debian-based images.

Parameters

NameTypeDescription
*packagesstrA variable number of strings, each representing an APT package name (e.g., 'curl', 'git').
secret_mountsOptional[SecretRequest] = NoneA list of secret requests to mount during the image build process, useful for accessing private APT repositories.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified APT packages installed.

with_commands()

@classmethod
def with_commands(
commands: List[str],
secret_mounts: Optional[SecretRequest] = None
) - > [Image](image.md?sid=flyte__image_image)

Creates a new Image instance that executes a list of shell commands during the image build process. This method provides a way to run arbitrary shell commands for custom setup or configuration within the container.

Parameters

NameTypeDescription
commandsList[str]A list of strings, where each string is a shell command to be executed. Do not include 'RUN' in the commands.
secret_mountsOptional[SecretRequest] = NoneA list of secret requests to mount during the image build process, useful for commands requiring sensitive information.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object with the specified commands configured to run during build.

with_local_v2()

@classmethod
def with_local_v2() - > [Image](image.md?sid=flyte__image_image)

Configures the image to use the local v2 builder, typically for local development and testing. This method ensures that the image is set up to work with the local Flyte v2 environment.

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured for local v2 execution.

with_local_v2_plugins()

@classmethod
def with_local_v2_plugins(
plugins: str | list[str]| None = None
) - > [Image](image.md?sid=flyte__image_image)

Configures the image to include specified Flyte v2 plugins for local development. This method allows you to add specific plugin functionalities to your local v2 environment.

Parameters

NameTypeDescription
plugins`strlist[str]

Returns

TypeDescription
[Image](image.md?sid=flyte__image_image)A new Image object configured with the specified local v2 plugins.