flytekit.ContainerTask

class flytekit.ContainerTask(*args, **kwargs)[source]

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.

Parameters
  • task_type (str) – defines a unique task-type for every new extension. If a backend plugin is required then this has to be done in-concert with the backend plugin identifier

  • name (str) – A unique name for the task instantiation. This is unique for every instance of task.

  • task_config (T) – Configuration for the task. This is used to configure the specific plugin that handles this task

  • interface (Optional[Interface]) – A python native typed interface (inputs) -> outputs that declares the signature of the task

  • environment (Optional[Dict[str, str]]) – Any environment variables that should be supplied during the execution of the task. Supplied as a dictionary of key/value pairs

Methods

compile(ctx, *args, **kwargs)

Generates a node that encapsulates this task in a workflow definition.

Parameters

ctx (flytekit.core.context_manager.FlyteContext) –

construct_node_metadata()

Used when constructing the node that encapsulates this task as part of a broader workflow definition.

Return type

flytekit.models.core.workflow.NodeMetadata

dispatch_execute(ctx, input_literal_map)

This method translates Flyte’s Type system based input values and invokes the actual call to the executor This method is also invoked during runtime.

  • VoidPromise is returned in the case when the task itself declares no outputs.

  • Literal Map is returned when the task returns either one more outputs in the declaration. Individual outputs may be none

  • DynamicJobSpec is returned when a dynamic workflow is executed

Parameters
Return type

Union[flytekit.models.core.literals.LiteralMap, flytekit.models.core.dynamic_job.DynamicJobSpec]

execute(**kwargs)[source]

This method will be invoked to execute the task.

Return type

Any

find_lhs()
Return type

str

get_config(settings)

Returns the task config as a serializable dictionary. This task config consists of metadata about the custom defined for this task.

Parameters

settings (flytekit.core.context_manager.SerializationSettings) –

Return type

Dict[str, str]

get_container(settings)[source]

Returns the container definition (if any) that is used to run the task on hosted Flyte.

Parameters

settings (flytekit.core.context_manager.SerializationSettings) –

Return type

flytekit.models.core.task.Container

get_custom(settings)

Return additional plugin-specific custom data (if any) as a serializable dictionary.

Parameters

settings (flytekit.core.context_manager.SerializationSettings) –

Return type

Dict[str, Any]

get_input_types()

Returns the names and python types as a dictionary for the inputs of this task.

Return type

Optional[Dict[str, type]]

get_k8s_pod(settings)

Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte.

Parameters

settings (flytekit.core.context_manager.SerializationSettings) –

Return type

flytekit.models.core.task.K8sPod

get_sql(settings)

Returns the Sql definition (if any) that is used to run the task on hosted Flyte.

Parameters

settings (flytekit.core.context_manager.SerializationSettings) –

Return type

Optional[flytekit.models.core.task.Sql]

get_type_for_input_var(k, v)

Returns the python type for an input variable by name.

Parameters
  • k (str) –

  • v (Any) –

Return type

Optional[Type[Any]]

get_type_for_output_var(k, v)

Returns the python type for the specified output variable by name.

Parameters
  • k (str) –

  • v (Any) –

Return type

Optional[Type[Any]]

local_execute(ctx, **kwargs)

This function is used only in the local execution path and is responsible for calling dispatch execute. Use this function when calling a task with native values (or Promises containing Flyte literals derived from Python native values).

Parameters

ctx (flytekit.core.context_manager.FlyteContext) –

Return type

Union[Tuple[flytekit.core.promise.Promise], flytekit.core.promise.Promise, flytekit.core.promise.VoidPromise]

post_execute(user_params, rval)

Post execute is called after the execution has completed, with the user_params and can be used to clean-up, or alter the outputs to match the intended tasks outputs. If not overridden, then this function is a No-op

Parameters
Return type

Any

pre_execute(user_params)

This is the method that will be invoked directly before executing the task method and before all the inputs are converted. One particular case where this is useful is if the context is to be modified for the user process to get some user space parameters. This also ensures that things like SparkSession are already correctly setup before the type transformers are called

This should return either the same context of the mutated context

Parameters

user_params (flytekit.common.tasks.sdk_runnable.ExecutionParameters) –

Return type

flytekit.common.tasks.sdk_runnable.ExecutionParameters

Attributes

environment

Any environment variables that supplied during the execution of the task.

instantiated_in
interface
lhs
location
metadata
name
python_interface

Returns this task’s python interface.

resources
security_context
task_config

Returns the user-specified task config which is used for plugin-specific handling of the task.

task_type
task_type_version