kfp.components package

class kfp.components.ComponentStore(local_search_paths=None, url_search_prefixes=None)[source]

Bases: object

load_component(name, digest=None, tag=None)[source]

Loads component local file or URL and creates a task factory function

Search locations: <local-search-path>/<name>/component.yaml <url-search-prefix>/<name>/component.yaml

If the digest is specified, then the search locations are: <local-search-path>/<name>/versions/sha256/<digest> <url-search-prefix>/<name>/versions/sha256/<digest>

If the tag is specified, then the search locations are: <local-search-path>/<name>/versions/tags/<digest> <url-search-prefix>/<name>/versions/tags/<digest>

Parameters:
  • name – Component name used to search and load the component artifact containing the component definition. Component name usually has the following form: group/subgroup/component
  • digest – Strict component version. SHA256 hash digest of the component artifact file. Can be used to load a specific component version so that the pipeline is reproducible.
  • tag – Version tag. Can be used to load component version from a specific branch. The version of the component referenced by a tag can change in future.
Returns:

A factory function with a strongly-typed signature. Once called with the required arguments, the factory constructs a pipeline task instance (ContainerOp).

load_component_from_file(path)[source]
load_component_from_url(url)[source]
kfp.components.func_to_component_text(func, extra_code='', base_image='tensorflow/tensorflow:1.11.0-py3')[source]

Converts a Python function to a component definition and returns its textual representation

Function docstring is used as component description. Argument and return annotations are used as component input/output types. To declare a function with multiple return values, use the NamedTuple return annotation syntax:

from typing import NamedTuple def add_multiply_two_numbers(a: float, b: float) -> NamedTuple(‘DummyName’, [(‘sum’, float), (‘product’, float)]):

“”“Returns sum and product of two arguments”“” return (a + b, a * b)
Parameters:
  • func – The python function to convert
  • base_image – Optional. Specify a custom Docker container image to use in the component. For lightweight components, the image needs to have python 3.5+. Default is tensorflow/tensorflow:1.11.0-py3 Note: The image can also be specified by decorating the function with the @python_component decorator. If different base images are explicitly specified in both places, an error is raised.
  • extra_code – Optional. Extra code to add before the function code. Can be used as workaround to define types used in function signature.
Returns:

Textual representation of a component definition

kfp.components.func_to_container_op(func, output_component_file=None, base_image='tensorflow/tensorflow:1.11.0-py3', extra_code='')[source]

Converts a Python function to a component and returns a task (ContainerOp) factory

Function docstring is used as component description. Argument and return annotations are used as component input/output types. To declare a function with multiple return values, use the NamedTuple return annotation syntax:

from typing import NamedTuple def add_multiply_two_numbers(a: float, b: float) -> NamedTuple(‘DummyName’, [(‘sum’, float), (‘product’, float)]):

“”“Returns sum and product of two arguments”“” return (a + b, a * b)
Parameters:
  • func – The python function to convert
  • base_image – Optional. Specify a custom Docker container image to use in the component. For lightweight components, the image needs to have python 3.5+. Default is tensorflow/tensorflow:1.11.0-py3 Note: The image can also be specified by decorating the function with the @python_component decorator. If different base images are explicitly specified in both places, an error is raised.
  • output_component_file – Optional. Write a component definition to a local file. Can be used for sharing.
  • extra_code – Optional. Extra code to add before the function code. Can be used as workaround to define types used in function signature.
Returns:

A factory function with a strongly-typed signature taken from the python function. Once called with the required arguments, the factory constructs a pipeline task instance (ContainerOp) that can run the original function in a container.

kfp.components.load_component(filename=None, url=None, text=None)[source]

Loads component from text, file or URL and creates a task factory function

Only one argument should be specified.

Parameters:
  • filename – Path of local file containing the component definition.
  • url – The URL of the component file data
  • text – A string containing the component file data.
Returns:

A factory function with a strongly-typed signature. Once called with the required arguments, the factory constructs a pipeline task instance (ContainerOp).

kfp.components.load_component_from_file(filename)[source]

Loads component from file and creates a task factory function

Parameters:filename – Path of local file containing the component definition.
Returns:A factory function with a strongly-typed signature. Once called with the required arguments, the factory constructs a pipeline task instance (ContainerOp).
kfp.components.load_component_from_text(text)[source]

Loads component from text and creates a task factory function

Parameters:text – A string containing the component file data.
Returns:A factory function with a strongly-typed signature. Once called with the required arguments, the factory constructs a pipeline task instance (ContainerOp).
kfp.components.load_component_from_url(url)[source]

Loads component from URL and creates a task factory function

Parameters:url – The URL of the component file data
Returns:A factory function with a strongly-typed signature. Once called with the required arguments, the factory constructs a pipeline task instance (ContainerOp).