kfp.components

The kfp.components module contains functions for loading components from compiled YAML.

Functions:

load_component_from_file(file_path)

Loads a component from a file.

load_component_from_url(url[, auth])

Loads a component from a URL.

load_component_from_text(text)

Loads a component from text.

Classes:

PythonComponent(component_spec, python_func)

A component defined via Python function.

BaseComponent(component_spec)

Base class for a component.

ContainerComponent(component_spec, pipeline_func)

Component defined via pre-built container.

YamlComponent(component_spec, component_yaml)

A component loaded from a YAML file.

kfp.components.load_component_from_file(file_path: str) YamlComponent[source]

Loads a component from a file.

Parameters
file_path : str

Filepath to a YAML component.

Returns

Component loaded from YAML.

Example

from kfp import components

components.load_component_from_file('~/path/to/pipeline.yaml')
kfp.components.load_component_from_url(url: str, auth: tuple[str, str] | None = None) YamlComponent[source]

Loads a component from a URL.

Parameters
url : str

URL to a YAML component.

auth : Tuple[str, str], optional

A ('<username>', '<password>') tuple of authentication credentials necessary for URL access. See Requests Authorization for more information.

Returns

Component loaded from YAML.

Example

from kfp import components

components.load_component_from_url('https://raw.githubusercontent.com/kubeflow/pipelines/7b49eadf621a9054e1f1315c86f95fb8cf8c17c3/sdk/python/kfp/compiler/test_data/components/identity.yaml')

components.load_component_from_url('gs://path/to/pipeline.yaml')
kfp.components.load_component_from_text(text: str) YamlComponent[source]

Loads a component from text.

Parameters
text : str

Component YAML text.

Returns

Component loaded from YAML.

class kfp.components.PythonComponent(component_spec: ComponentSpec, python_func: Callable)[source]

Bases: BaseComponent

A component defined via Python function.

Note: PythonComponent is not intended to be used to construct components directly. Use @kfp.dsl.component instead.

Parameters
component_spec: ComponentSpec

Component definition.

python_func: Callable

Python function that becomes the implementation of this component.

Methods:

execute(**kwargs)

Executes the Python function that defines the component.

execute(**kwargs)[source]

Executes the Python function that defines the component.

class kfp.components.BaseComponent(component_spec: ComponentSpec)[source]

Bases: ABC

Base class for a component.

Note: BaseComponent is not intended to be used to construct components directly. Use @kfp.dsl.component or kfp.components.load_component_from_*() instead.

name

Name of the component.

component_spec

Component definition.

Attributes:

pipeline_spec

Returns the pipeline spec of the component.

platform_spec

Returns the PlatformSpec of the component.

required_inputs

Methods:

execute(**kwargs)

Executes the component locally if implemented by the inheriting subclass.

property pipeline_spec : PipelineSpec

Returns the pipeline spec of the component.

property platform_spec : PlatformSpec

Returns the PlatformSpec of the component.

Useful when the component is a GraphComponent, else will be empty per component_spec.platform_spec default.

abstract execute(**kwargs)[source]

Executes the component locally if implemented by the inheriting subclass.

property required_inputs : list[str]
class kfp.components.ContainerComponent(component_spec: ComponentSpec, pipeline_func: Callable)[source]

Bases: BaseComponent

Component defined via pre-built container.

Attribute:

pipeline_func: The function that becomes the implementation of this component.

Methods:

execute(**kwargs)

Executes the component locally if implemented by the inheriting subclass.

execute(**kwargs)[source]

Executes the component locally if implemented by the inheriting subclass.

class kfp.components.YamlComponent(component_spec: ComponentSpec, component_yaml: str)[source]

Bases: BaseComponent

A component loaded from a YAML file.

Note: YamlComponent is not intended to be used to construct components directly. Use kfp.components.load_component_from_*() instead.

Attribute:

component_spec: Component definition. component_yaml: The yaml string that this component is loaded from.

Attributes:

pipeline_spec

Returns the pipeline spec of the component.

Methods:

execute(*args, **kwargs)

Not implemented.

property pipeline_spec : PipelineSpec

Returns the pipeline spec of the component.

execute(*args, **kwargs)[source]

Not implemented.