Skip to main content

ContainerTask

This is an intermediate class that represents Flyte Tasks that run a container at execution time. This is the vast majority of tasks - the typical @task decorated tasks; for instance, all run a container. An example of something that doesn't run a container would be something like the Athena SQL task.

Attributes​

AttributeTypeDescription
MetadataFormatLiteral["JSON", "YAML", "PROTO"]The format of the output file. This can be "JSON", "YAML", or "PROTO".
local_logsbool = TrueIf True, logs will be printed to the console in the local execution.

Constructor​

Signature​

def ContainerTask(
name: str,
image: Union[str, [Image](../../image/image.md?sid=flyte__image_image)],
command: List[str],
inputs: Optional[Dict[str, Type]] = None,
arguments: Optional[List[str]] = None,
outputs: Optional[Dict[str, Type]] = None,
input_data_dir: str | pathlib.Path = "/var/inputs",
output_data_dir: str | pathlib.Path = "/var/outputs",
metadata_format: MetadataFormat = "JSON",
local_logs: bool = True,
block_network: bool = False
) - > null

Parameters​

NameTypeDescription
namestrName of the task
imageUnion[str, [Image](../../image/image.md?sid=flyte__image_image)]The container image to use for the task.
commandList[str]The command to run in the container.
inputsOptional[Dict[str, Type]] = NoneThe inputs to the task as a dictionary of names to types.
argumentsOptional[List[str]] = NoneThe arguments to pass to the command.
outputsOptional[Dict[str, Type]] = NoneThe outputs of the task as a dictionary of names to types.
input_data_dir`strpathlib.Path` = "/var/inputs"
output_data_dir`strpathlib.Path` = "/var/outputs"
metadata_formatMetadataFormat = "JSON"The format of the output file (JSON, YAML, or PROTO).
local_logsbool = TrueIf True, logs will be printed to the console in local execution.
block_networkbool = FalseIf True, blocks all outbound network access.

Methods​


execute()​

@classmethod
def execute(
kwargs: Any
) - > Any

Executes the task locally by running a Docker container with the specified image, commands, and volume mounts.

Parameters​

NameTypeDescription
kwargsAnyThe input values provided to the task for execution.

Returns​

TypeDescription
AnyThe processed outputs of the task execution.

data_loading_config()​

@classmethod
def data_loading_config(
sctx: [SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > tasks_pb2.DataLoadingConfig

Generates the data loading configuration for the task, specifying input/output paths and metadata formats for the Flyte engine.

Parameters​

NameTypeDescription
sctx[SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext)The context used during the serialization of the task.

Returns​

TypeDescription
tasks_pb2.DataLoadingConfigA protobuf message containing the data loading specifications.

container_args()​

@classmethod
def container_args(
sctx: [SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext)
) - > List[str]

Constructs the full list of arguments to be passed to the container by combining the base command and additional arguments.

Parameters​

NameTypeDescription
sctx[SerializationContext](../../models/serializationcontext.md?sid=flyte_models_serializationcontext)The context used during the serialization of the task.

Returns​

TypeDescription
List[str]A list of strings representing the complete command and arguments for the container.