flytekit.core.python_function_task.PythonFunctionTask#
- class flytekit.core.python_function_task.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 when serialized on the hosted Flyte platform handles the writing 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.
- Parameters
task_config (T) – Configuration object for Task. Should be a unique type for that specific Task
task_function (Callable) – Python function that has type annotations and works for the task
ignore_input_vars (Optional[List[str]]) – 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
execution_mode (Optional[ExecutionBehavior]) – Defines how the execution should behave, for example executing normally or specially handling a dynamic case.
task_type (str) – String task type to be associated with this Task
- __init__(task_config, task_function, task_type='python-task', ignore_input_vars=None, execution_mode=ExecutionBehavior.DEFAULT, task_resolver=None, **kwargs)[source]#
- Parameters
task_config (T) – Configuration object for Task. Should be a unique type for that specific Task
task_function (Callable) – Python function that has type annotations and works for the task
ignore_input_vars (Optional[List[str]]) – 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
execution_mode (Optional[ExecutionBehavior]) – Defines how the execution should behave, for example executing normally or specially handling a dynamic case.
task_type (str) – String task type to be associated with this Task
task_resolver (Optional[flytekit.core.base_task.TaskResolverMixin]) –
Methods
__init__
(task_config, task_function[, ...])- param T task_config
Configuration object for Task. Should be a unique type for that specific Task
compile
(ctx, *args, **kwargs)Generates a node that encapsulates this task in a workflow definition.
compile_into_workflow
(ctx, task_function, ...)In the case of dynamic workflows, this function will produce a workflow definition at execution time which will then proceed to be executed.
construct_node_metadata
()Used when constructing the node that encapsulates this task as part of a broader workflow definition.
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)Returns the command which should be used in the container definition for the serialized version of this task registered on a hosted Flyte platform.
get_config
(settings)Returns the task config as a serializable dictionary.
get_container
(settings)Returns the container definition (if any) that is used to run the task on hosted Flyte.
get_custom
(settings)Return additional plugin-specific custom data (if any) as a serializable dictionary.
get_default_command
(settings)Returns the default pyflyte-execute command used to run this on hosted Flyte platforms.
get_input_types
()Returns the names and python types as a dictionary for the inputs of this task.
get_k8s_pod
(settings)Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte.
get_sql
(settings)Returns the Sql definition (if any) that is used to run the task on hosted Flyte.
get_type_for_input_var
(k, v)Returns the python type for an input variable by name.
get_type_for_output_var
(k, v)Returns the python type for the specified output variable by name.
local_execute
(ctx, **kwargs)This function is used only in the local execution path and is responsible for calling dispatch execute.
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.
reset_command_fn
()Resets the command which should be used in the container definition of this task to the default arguments.
sandbox_execute
(ctx, input_literal_map)Call dispatch_execute, in the context of a local sandbox execution.
set_command_fn
([get_command_fn])By default, the task will run on the Flyte platform using the pyflyte-execute command.
Attributes
container_image
disable_deck
If true, this task will not output deck html file
docs
environment
Any environment variables that supplied during the execution of the task.
execution_mode
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_function
task_resolver
task_type
task_type_version