Lightweight Python components do not require you to build a new container image for every code change. They’re intended for fast iteration in a notebook environment.
Advantages over container components:
To build a component, define a stand-alone Python function and then call
kfp.components.func_to_container_op(func) to convert the function to a
component that can be used in a pipeline.
There are several requirements for the component function:
The function must be stand-alone.
The function can only import packages that are available in the base image.
subprocessmodule to run
pip installfor the required package.)
If the function operates on numbers, the parameters must have type hints.
Supported types are
bool. All other arguments are passed as
To build a component with multiple output values, use Python’s typing.NamedTuple type hint syntax:
NamedTuple('MyFunctionOutputs', [('output_name_1', type), ('output_name_2', float)])
NamedTuple class is already imported, so that it can be used in the
See the notebook on lightweight Python component basics for an example of creating lightweight Python components and using them in a pipeline.