ImageSpec
During the development cycle you will want to be able to run your workflows both locally on your machine and remotely on Flyte, so you will need to ensure that the required dependencies are installed in both environments.
Here we will explain how to set up the dependencies for your workflow to run remotely on Flyte. For information on how to make your dependencies available locally, see Local dependencies.
When a workflow is deployed to Flyte, each task is set up to run in its own container in the Kubernetes cluster.
You specify the dependencies as part of the definition of the container image to be used for each task using the ImageSpec class.
For example::
import flytekit as fl
image_spec = union.ImageSpec(
name="say-hello-image",
requirements="uv.lock",
)
@fl.task(container_image=image_spec)
def say_hello(name: str) -> str:
return f"Hello, {name}!"
@fl.workflow
def hello_world_wf(name: str = "world") -> str:
greeting = say_hello(name=name)
return greetingHere, the ImageSpec class is used to specify the container image to be used for the say_hello task.
-
The
nameparameter specifies the name of the image. This name will be used to identify the image in the container registry. -
The
requirementsparameter specifies the path to a file (relative to the directory in which thepyflyte runorpyflyte registercommand is invoked) that specifies the dependencies to be installed in the image. The file may be:- A
requirements.txtfile. - A
uv.lockfile generated by theuv synccommand. - A
poetry.lockfile generated by thepoetry installcommand. - A
pyproject.tomlfile.
- A
When you execute the pyflyte run or pyflyte register command, Flyte will build the container image defined in ImageSpec block
(as well as registering the tasks and workflows defined in your code).