flytekit.core.python_auto_container
| Property |
Type |
Description |
PICKLE_FILE_PATH |
str |
|
RUNTIME_PACKAGES_ENV_NAME |
str |
|
T |
TypeVar |
|
default_notebook_task_resolver |
DefaultNotebookTaskResolver |
|
default_task_resolver |
DefaultTaskResolver |
|
def get_registerable_container_image(
img: Optional[Union[str, ImageSpec]],
cfg: ImageConfig,
) -> str
Resolve the image to the real image name that should be used for registration.
- If img is a ImageSpec, it will be built and the image name will be returned
- If img is a placeholder string (e.g. {{.image.default.fqn}}:{{.image.default.version}}),
it will be resolved using the cfg and the image name will be returned
| Parameter |
Type |
Description |
img |
Optional[Union[str, ImageSpec]] |
Configured image or image spec |
cfg |
ImageConfig |
Registration configuration |
def update_image_spec_copy_handling(
image_spec: ImageSpec,
settings: SerializationSettings,
)
This helper function is where the relationship between fast register and ImageSpec is codified.
If fast register is not enabled, then source root is used and then files are copied.
See the copy option in ImageSpec for more information.
Currently the relationship is incidental. Because serialization settings are not passed into the image spec
build command (and it probably shouldn’t be), the builder has no concept of which files to copy, when, and
from where. (or to where but that is hard-coded)
| Parameter |
Type |
Description |
image_spec |
ImageSpec |
|
settings |
SerializationSettings |
|
This resolved is used when the task is defined in a notebook. It is used to load the task from the notebook.
class DefaultNotebookTaskResolver(
args,
kwargs,
)
| Parameter |
Type |
Description |
args |
*args |
|
kwargs |
**kwargs |
|
| Property |
Type |
Description |
instantiated_in |
str |
|
lhs |
None |
|
location |
str |
|
| Method |
Description |
find_lhs() |
|
get_all_tasks() |
Future proof method. |
load_task() |
Given the set of identifier keys, should return one Python Task or raise an error if not found. |
loader_args() |
Return a list of strings that can help identify the parameter Task. |
name() |
|
task_name() |
Overridable function that can optionally return a custom name for a given task. |
Future proof method. Just making it easy to access all tasks (Not required today as we auto register them)
def load_task(
loader_args: List[str],
) -> PythonAutoContainerTask
Given the set of identifier keys, should return one Python Task or raise an error if not found
| Parameter |
Type |
Description |
loader_args |
List[str] |
|
def loader_args(
settings: SerializationSettings,
task: PythonAutoContainerTask,
) -> List[str]
Return a list of strings that can help identify the parameter Task
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
task |
PythonAutoContainerTask |
|
def task_name(
t: flytekit.core.base_task.Task,
) -> typing.Optional[str]
Overridable function that can optionally return a custom name for a given task
| Parameter |
Type |
Description |
t |
flytekit.core.base_task.Task |
|
Please see the notes in the TaskResolverMixin as it describes this default behavior.
class DefaultTaskResolver(
args,
kwargs,
)
| Parameter |
Type |
Description |
args |
*args |
|
kwargs |
**kwargs |
|
| Property |
Type |
Description |
instantiated_in |
str |
|
lhs |
None |
|
location |
str |
|
| Method |
Description |
find_lhs() |
|
get_all_tasks() |
Future proof method. |
load_task() |
Given the set of identifier keys, should return one Python Task or raise an error if not found. |
loader_args() |
Return a list of strings that can help identify the parameter Task. |
name() |
|
task_name() |
Overridable function that can optionally return a custom name for a given task. |
Future proof method. Just making it easy to access all tasks (Not required today as we auto register them)
def load_task(
loader_args: List[str],
) -> PythonAutoContainerTask
Given the set of identifier keys, should return one Python Task or raise an error if not found
| Parameter |
Type |
Description |
loader_args |
List[str] |
|
def loader_args(
settings: SerializationSettings,
task: PythonAutoContainerTask,
) -> List[str]
Return a list of strings that can help identify the parameter Task
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
task |
PythonAutoContainerTask |
|
def task_name(
t: flytekit.core.base_task.Task,
) -> typing.Optional[str]
Overridable function that can optionally return a custom name for a given task
| Parameter |
Type |
Description |
t |
flytekit.core.base_task.Task |
|
Represents the structure of the pickled object stored in the .pkl file for interactive mode.
class PickledEntity(
metadata: PickledEntityMetadata,
entities: Dict[str, PythonAutoContainerTask],
)
| Parameter |
Type |
Description |
metadata |
PickledEntityMetadata |
Metadata about the pickled entities including Python version |
entities |
Dict[str, PythonAutoContainerTask] |
Dictionary mapping entity names to their PythonAutoContainerTask instances |
Metadata for a pickled entity containing version information.
class PickledEntityMetadata(
python_version: str,
)
| Parameter |
Type |
Description |
python_version |
str |
The Python version string (e.g. “3.12.0”) used to create the pickle |
A Python AutoContainer task should be used as the base for all extensions that want the user’s code to be in the
container and the container information to be automatically captured.
This base will auto configure the image and image version to be used for all its derivatives.
If you are looking to extend, you might prefer to use PythonFunctionTask or PythonInstanceTask
class PythonAutoContainerTask(
name: str,
task_config: T,
task_type,
container_image: Optional[Union[str, ImageSpec]],
requests: Optional[Resources],
limits: Optional[Resources],
environment: Optional[Dict[str, str]],
task_resolver: Optional[TaskResolverMixin],
secret_requests: Optional[List[Secret]],
pod_template: Optional[PodTemplate],
pod_template_name: Optional[str],
accelerator: Optional[BaseAccelerator],
shared_memory: Optional[Union[L[True], str]],
resources: Optional[Resources],
kwargs,
)
| Parameter |
Type |
Description |
name |
str |
unique name for the task, usually the function’s module and name. |
task_config |
T |
Configuration object for Task. Should be a unique type for that specific Task. |
task_type |
|
String task type to be associated with this Task |
container_image |
Optional[Union[str, ImageSpec]] |
String FQN for the image. |
requests |
Optional[Resources] |
custom resource request settings. |
limits |
Optional[Resources] |
custom resource limit settings. |
environment |
Optional[Dict[str, str]] |
Environment variables you want the task to have when run. |
task_resolver |
Optional[TaskResolverMixin] |
Custom resolver - will pick up the default resolver if empty, or the resolver set in the compilation context if one is set. |
secret_requests |
Optional[List[Secret]] |
|
pod_template |
Optional[PodTemplate] |
Custom PodTemplate for this task. |
pod_template_name |
Optional[str] |
The name of the existing PodTemplate resource which will be used in this task. |
accelerator |
Optional[BaseAccelerator] |
The accelerator to use for this task. |
shared_memory |
Optional[Union[L[True], str]] |
If True, then shared memory will be attached to the container where the size is equal to the allocated memory. If str, then the shared memory is set to that size. |
resources |
Optional[Resources] |
Specify both the request and the limit. When the value is set to a tuple or list, the first value is the request and the second value is the limit. If the value is a single value, then both the requests and limit is set to that value. For example, the Resource(cpu=("1", "2"), mem="1Gi") will set the cpu request to 1, cpu limit to 2, and mem request to 1Gi. |
kwargs |
**kwargs |
|
| Property |
Type |
Description |
container_image |
Optional[Union[str, ImageSpec]] |
|
deck_fields |
typing.List[flytekit.deck.deck.DeckField] |
If not empty, this task will output deck html file for the specified decks |
disable_deck |
bool |
If true, this task will not output deck html file |
docs |
flytekit.models.documentation.Documentation |
|
enable_deck |
bool |
If true, this task will output deck html file |
environment |
typing.Dict[str, str] |
Any environment variables that supplied during the execution of the task. |
instantiated_in |
str |
|
interface |
flytekit.models.interface.TypedInterface |
|
lhs |
None |
|
location |
str |
|
metadata |
flytekit.core.base_task.TaskMetadata |
|
name |
str |
|
python_interface |
flytekit.core.interface.Interface |
Returns this task’s python interface. |
resources |
ResourceSpec |
|
security_context |
flytekit.models.security.SecurityContext |
|
task_config |
typing.Optional[~T] |
Returns the user-specified task config which is used for plugin-specific handling of the task. |
task_resolver |
TaskResolverMixin |
|
task_type |
str |
|
task_type_version |
int |
|
| Method |
Description |
compile() |
Generates a node that encapsulates this task in a workflow definition. |
construct_node_metadata() |
Used when constructing the node that encapsulates this task as part of a broader workflow definition. |
dispatch_execute() |
This method translates Flyte’s Type system based input values and invokes the actual call to the executor. |
execute() |
This method will be invoked to execute the task. |
find_lhs() |
|
get_command() |
Returns the command which should be used in the container definition for the serialized version of this task. |
get_config() |
Returns the task config as a serializable dictionary. |
get_container() |
Returns the container definition (if any) that is used to run the task on hosted Flyte. |
get_custom() |
Return additional plugin-specific custom data (if any) as a serializable dictionary. |
get_default_command() |
Returns the default pyflyte-execute command used to run this on hosted Flyte platforms. |
get_extended_resources() |
Returns the extended resources to allocate to the task on hosted Flyte. |
get_image() |
Update image spec based on fast registration usage, and return string representing the image. |
get_input_types() |
Returns the names and python types as a dictionary for the inputs of this task. |
get_k8s_pod() |
Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte. |
get_sql() |
Returns the Sql definition (if any) that is used to run the task on hosted Flyte. |
get_type_for_input_var() |
Returns the python type for an input variable by name. |
get_type_for_output_var() |
Returns the python type for the specified output variable by name. |
local_execute() |
This function is used only in the local execution path and is responsible for calling dispatch execute. |
local_execution_mode() |
|
post_execute() |
Post execute is called after the execution has completed, with the user_params and can be used to clean-up,. |
pre_execute() |
This is the method that will be invoked directly before executing the task method and before all the inputs. |
reset_command_fn() |
Resets the command which should be used in the container definition of this task to the default arguments. |
sandbox_execute() |
Call dispatch_execute, in the context of a local sandbox execution. |
set_command_fn() |
By default, the task will run on the Flyte platform using the pyflyte-execute command. |
set_resolver() |
By default, flytekit uses the DefaultTaskResolver to resolve the task. |
def compile(
ctx: flytekit.core.context_manager.FlyteContext,
args,
kwargs,
) -> typing.Union[typing.Tuple[flytekit.core.promise.Promise], flytekit.core.promise.Promise, flytekit.core.promise.VoidPromise, NoneType]
Generates a node that encapsulates this task in a workflow definition.
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
args |
*args |
|
kwargs |
**kwargs |
|
def construct_node_metadata()
Used when constructing the node that encapsulates this task as part of a broader workflow definition.
def dispatch_execute(
ctx: flytekit.core.context_manager.FlyteContext,
input_literal_map: flytekit.models.literals.LiteralMap,
) -> typing.Union[flytekit.models.literals.LiteralMap, flytekit.models.dynamic_job.DynamicJobSpec, typing.Coroutine]
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
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
input_literal_map |
flytekit.models.literals.LiteralMap |
|
def execute(
kwargs,
) -> typing.Any
This method will be invoked to execute the task.
| Parameter |
Type |
Description |
kwargs |
**kwargs |
|
def get_command(
settings: SerializationSettings,
) -> List[str]
Returns the command which should be used in the container definition for the serialized version of this task
registered on a hosted Flyte platform.
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
def get_config(
settings: SerializationSettings,
) -> Optional[Dict[str, str]]
Returns the task config as a serializable dictionary. This task config consists of metadata about the custom
defined for this task.
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
def get_container(
settings: SerializationSettings,
) -> _task_model.Container
Returns the container definition (if any) that is used to run the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
def get_custom(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Optional[typing.Dict[str, typing.Any]]
Return additional plugin-specific custom data (if any) as a serializable dictionary.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_default_command(
settings: SerializationSettings,
) -> List[str]
Returns the default pyflyte-execute command used to run this on hosted Flyte platforms.
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
def get_extended_resources(
settings: SerializationSettings,
) -> Optional[tasks_pb2.ExtendedResources]
Returns the extended resources to allocate to the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
def get_image(
settings: SerializationSettings,
) -> str
Update image spec based on fast registration usage, and return string representing the image
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
Returns the names and python types as a dictionary for the inputs of this task.
def get_k8s_pod(
settings: SerializationSettings,
) -> _task_model.K8sPod
Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
SerializationSettings |
|
def get_sql(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Optional[flytekit.models.task.Sql]
Returns the Sql definition (if any) that is used to run the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_type_for_input_var(
k: str,
v: typing.Any,
) -> typing.Type[typing.Any]
Returns the python type for an input variable by name.
| Parameter |
Type |
Description |
k |
str |
|
v |
typing.Any |
|
def get_type_for_output_var(
k: str,
v: typing.Any,
) -> typing.Type[typing.Any]
Returns the python type for the specified output variable by name.
| Parameter |
Type |
Description |
k |
str |
|
v |
typing.Any |
|
def local_execute(
ctx: flytekit.core.context_manager.FlyteContext,
kwargs,
) -> typing.Union[typing.Tuple[flytekit.core.promise.Promise], flytekit.core.promise.Promise, flytekit.core.promise.VoidPromise, typing.Coroutine, NoneType]
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).
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
kwargs |
**kwargs |
|
def local_execution_mode()
def post_execute(
user_params: typing.Optional[flytekit.core.context_manager.ExecutionParameters],
rval: typing.Any,
) -> typing.Any
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
| Parameter |
Type |
Description |
user_params |
typing.Optional[flytekit.core.context_manager.ExecutionParameters] |
are the modified user params as created during the pre_execute step |
rval |
typing.Any |
|
def pre_execute(
user_params: typing.Optional[flytekit.core.context_manager.ExecutionParameters],
) -> typing.Optional[flytekit.core.context_manager.ExecutionParameters]
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
| Parameter |
Type |
Description |
user_params |
typing.Optional[flytekit.core.context_manager.ExecutionParameters] |
|
Resets the command which should be used in the container definition of this task to the default arguments.
This is useful when the command line is overridden at serialization time.
def sandbox_execute(
ctx: flytekit.core.context_manager.FlyteContext,
input_literal_map: flytekit.models.literals.LiteralMap,
) -> flytekit.models.literals.LiteralMap
Call dispatch_execute, in the context of a local sandbox execution. Not invoked during runtime.
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
input_literal_map |
flytekit.models.literals.LiteralMap |
|
def set_command_fn(
get_command_fn: Optional[Callable[[SerializationSettings], List[str]]],
)
By default, the task will run on the Flyte platform using the pyflyte-execute command.
However, it can be useful to update the command with which the task is serialized for specific cases like
running map tasks (“pyflyte-map-execute”) or for fast-executed tasks.
| Parameter |
Type |
Description |
get_command_fn |
Optional[Callable[[SerializationSettings], List[str]]] |
|
def set_resolver(
resolver: TaskResolverMixin,
)
By default, flytekit uses the DefaultTaskResolver to resolve the task. This method allows the user to set a custom
task resolver. It can be useful to override the task resolver for specific cases like running tasks in the jupyter notebook.
| Parameter |
Type |
Description |
resolver |
TaskResolverMixin |
|