flytekit.extend.PythonCustomizedContainerTask#

class flytekit.extend.PythonCustomizedContainerTask(*args, **kwargs)[source]#

Please take a look at the comments for :py:class`flytekit.extend.ExecutableTemplateShimTask` as well. This class should be subclassed and a custom Executor provided as a default to this parent class constructor when building a new external-container flytekit-only plugin.

This class provides authors of new task types the basic scaffolding to create task-template based tasks. In order to write such a task, authors need to

  • subclass the ShimTaskExecutor class and override the execute_from_model function. This function is where all the business logic should go. Keep in mind though that you, the plugin author, will not have access to anything that’s not serialized within the TaskTemplate which is why you’ll also need to

  • subclass this class, and override the get_custom function to include all the information the executor will need to run.

  • Also pass the executor you created as the executor_type argument of this class’s constructor.

Keep in mind that the total size of the TaskTemplate still needs to be small, since these will be accessed frequently by the Flyte engine.

Methods

compile(ctx, *args, **kwargs)[source]#

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

Parameters:

ctx (FlyteContext)

Return type:

Tuple[Promise] | Promise | VoidPromise | None

construct_node_metadata()[source]#

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

Return type:

NodeMetadata

dispatch_execute(ctx, input_literal_map)[source]#

This function is largely similar to the base PythonTask, with the exception that we have to infer the Python interface before executing. Also, we refer to self.task_template rather than just self similar to task classes that derive from the base PythonTask.

Parameters:
Return type:

LiteralMap | DynamicJobSpec

execute(**kwargs)[source]#

Rather than running here, send everything to the executor.

Return type:

Any

find_lhs()[source]#
Return type:

str

get_command(settings)[source]#
Parameters:

settings (SerializationSettings)

Return type:

List[str]

get_config(settings)[source]#

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

Parameters:

settings (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 (SerializationSettings)

Return type:

Container

get_custom(settings)[source]#

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

Parameters:

settings (SerializationSettings)

Return type:

Dict[str, Any]

get_extended_resources(settings)[source]#

Returns the extended resources to allocate to the task on hosted Flyte.

Parameters:

settings (SerializationSettings)

Return type:

ExtendedResources | None

get_image(settings)[source]#
Parameters:

settings (SerializationSettings)

Return type:

str

get_input_types()[source]#

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

Return type:

Dict[str, type]

get_k8s_pod(settings)[source]#

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

Parameters:

settings (SerializationSettings)

Return type:

K8sPod | None

get_sql(settings)[source]#

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

Parameters:

settings (SerializationSettings)

Return type:

Sql | None

get_type_for_input_var(k, v)[source]#

Returns the python type for an input variable by name.

Parameters:
Return type:

Type[Any]

get_type_for_output_var(k, v)[source]#

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

Parameters:
Return type:

Type[Any]

local_execute(ctx, **kwargs)[source]#

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 (FlyteContext)

Return type:

Tuple[Promise] | Promise | VoidPromise | Coroutine | None

local_execution_mode()[source]#
Return type:

Mode

post_execute(_, rval)[source]#

This function is a stub, just here to keep dispatch_execute compatibility between this class and PythonTask.

Parameters:
Return type:

Any

pre_execute(user_params)[source]#

This function is a stub, just here to keep dispatch_execute compatibility between this class and PythonTask.

Parameters:

user_params (ExecutionParameters | None)

Return type:

ExecutionParameters | None

sandbox_execute(ctx, input_literal_map)[source]#

Call dispatch_execute, in the context of a local sandbox execution. Not invoked during runtime.

Parameters:
Return type:

LiteralMap

serialize_to_model(settings)[source]#
Parameters:

settings (SerializationSettings)

Return type:

TaskTemplate

Attributes

SERIALIZE_SETTINGS = SerializationSettings(image_config=ImageConfig(default_image=Image(name='custom_container_task', fqn='flyteorg.io/placeholder', tag='image', digest=None), images=None), project='PLACEHOLDER_PROJECT', domain='LOCAL', version='PLACEHOLDER_VERSION', env=None, git_repo=None, python_interpreter='/opt/venv/bin/python3', flytekit_virtualenv_root='/opt/venv', fast_serialization_settings=None, source_root=None)[source]
container_image
deck_fields

If not empty, this task will output deck html file for the specified decks

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.

executor
executor_type
instantiated_in
interface
lhs
location
metadata
name

Return the name of the underlying task.

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_resolver
task_template

Override the base class implementation to serialize on first call.

task_type
task_type_version