flytekit.PythonFunctionTask

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

A Python Function task should be used as the base for all extensions that have a python function. It will automatically detect interface of the python function and also, create the write execution command to execute the function

It is advised this task is used using the @task decorator as follows

In the above code, the name of the function, the module, and the interface (inputs = int and outputs = str) will be auto detected.

__init__(task_config: T, task_function: Callable, task_type='python-task', ignore_input_vars: Optional[List[str]] = None, execution_mode: Optional[flytekit.core.python_function_task.PythonFunctionTask.ExecutionBehavior] = <ExecutionBehavior.DEFAULT: 1>, task_resolver: Optional[flytekit.core.python_auto_container.TaskResolverMixin] = None, **kwargs)[source]
Parameters
  • task_config – Configuration object for Task. Should be a unique type for that specific Task

  • task_function – Python function that has type annotations and works for the task

  • ignore_input_vars – When supplied, these input variables will be removed from the interface. This can be used to inject some client side variables only. Prefer using ExecutionParams

  • task_type – String task type to be associated with this Task

Methods

__init__(task_config, task_function[, …])

param task_config

Configuration object for Task. Should be a unique type for that specific Task

aggregate(tasks, workflows, node)

compile(ctx, *args, **kwargs)

compile_into_workflow(ctx, …)

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.

dynamic_execute(task_function, **kwargs)

By the time this function is invoked, the _local_execute function should have unwrapped the Promises and Flyte literal wrappers so that the kwargs we are working with here are now Python native literal values.

execute(**kwargs)

This method will be invoked to execute the task.

find_lhs()

get_command(settings)

get_config(settings)

get_container(settings)

get_custom(settings)

get_input_types()

Returns python native types for inputs.

get_type_for_input_var(k, v)

Returns the python native type for the given input variable # TODO we could use literal type to determine this

get_type_for_output_var(k, v)

Returns the python native type for the given output variable # TODO we could use literal type to determine this

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.

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.

Attributes

container_image

environment

execution_mode

instantiated_in

interface

lhs

location

metadata

name

python_interface

resources

security_context

task_config

task_function

task_resolver

task_type

task_type_version