Getting started

Create your first pipeline

To get started with the tutorials, pip install kfp v2:

pip install kfp

Here is a simple pipeline that prints a greeting:

from kfp import dsl

@dsl.component
def say_hello(name: str) -> str:
    hello_text = f'Hello, {name}!'
    print(hello_text)
    return hello_text

@dsl.pipeline
def hello_pipeline(recipient: str) -> str:
    hello_task = say_hello(name=recipient)
    return hello_task.output

You can compile the pipeline to YAML with the KFP SDK DSL Compiler:

from kfp import compiler

compiler.Compiler().compile(hello_pipeline, 'pipeline.yaml')

The dsl.component and dsl.pipeline decorators turn your type-annotated Python functions into components and pipelines, respectively. The KFP SDK compiler compiles the domain-specific language (DSL) objects to a self-contained pipeline YAML file.

You can submit the YAML file to a KFP-conformant backend for execution. If you have already deployed a KFP open source backend instance and obtained the endpoint for your deployment, you can submit the pipeline for execution using the KFP SDK Client. The following submits the pipeline for execution with the argument recipient='World':

from kfp.client import Client

client = Client(host='<MY-KFP-ENDPOINT>')
run = client.create_run_from_pipeline_package(
    'pipeline.yaml',
    arguments={
        'recipient': 'World',
    },
)

The client will print a link to view the pipeline execution graph and logs in the UI. In this case, the pipeline has one task that prints and returns 'Hello, World!'.

In the next few sections, you’ll learn more about the core concepts of authoring pipelines and how to create more expressive, useful pipelines.

Feedback

Was this page helpful?


Last modified May 31, 2024: Regrouped user guides (350dde8a)