Kubeflow Pipelines Pipeline Specification
kfp-pipeline-spec defines the canonical data structures and protobuf messages for Kubeflow Pipelines (KFP) v2 pipeline specifications. It is a core component of the KFP SDK, providing the underlying schema for pipeline definitions compiled by `kfp` and executed on the KFP backend. The library is actively maintained, with releases frequently synchronised with the main KFP SDK, currently at version 2.16.0.
Common errors
-
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. kfp-pipeline-spec X.Y.Z requires protobuf<4,>=3.13.0, but you have protobuf A.B.C which is incompatible.
cause This error occurs due to conflicting `protobuf` package versions required by `kfp-pipeline-spec` and other installed libraries, leading to an incompatible dependency resolution.fixDowngrade or upgrade the `protobuf` package to a version compatible with `kfp-pipeline-spec` (e.g., `pip install protobuf==3.20.0`) or ensure all `kfp` related packages are installed with compatible versions, often by using a fresh virtual environment and pinning `kfp` to a specific version (e.g., `pip install kfp==2.7.0 kfp-pipeline-spec==0.3.0`). -
AttributeError: module 'kfp_server_api' has no attribute 'ApiPipelineSpec'
cause This `AttributeError` typically indicates a version mismatch or breaking API change between the `kfp` SDK, `kfp-pipeline-spec`, and `kfp-server-api` packages, where a newer version of the SDK or `kfp-pipeline-spec` expects an `ApiPipelineSpec` attribute that is not present or has been renamed in the installed `kfp_server_api` version.fixEnsure all Kubeflow Pipelines SDK components (`kfp`, `kfp-pipeline-spec`, `kfp-server-api`) are compatible by installing specific, known-good versions together, for example, `pip install kfp==2.0.0b12 kfp-pipeline-spec==0.1.16 kfp-server-api==2.0.0b0` or upgrading all KFP-related packages to their latest compatible versions (`pip install --upgrade kfp kfp-pipeline-spec kfp-server-api`). -
TypeError: Artifacts must have both a schema_title and a schema_version, separated by '@'. Got: float.
cause This `TypeError` arises in KFP v2 pipelines when a primitive type (like `float` or `str`) is used as an output from a component where an artifact type with a defined schema (`schema_title@schema_version`) is expected, or when the `__future__.annotations` import is used without proper handling for artifact types.fixExplicitly define the schema for artifact outputs using `Output[ArtifactType]` with a `schema_title` and `schema_version` (e.g., `Output[Artifact(schema_title='my.Schema', schema_version='1.0.0')]`) or, if applicable for simple parameters, ensure the `from __future__ import annotations` import is not causing type annotation misinterpretations, potentially by removing it if not strictly needed. For list and dict inputs/outputs, ensure KFP version supports them or remove explicit type hints like `list[int]` to `list`. -
NotImplementedError: Input argument supports only the following types: PipelineParam, str, int, float, bool, dict, and list. Got: "None".
cause This `NotImplementedError` occurs during pipeline compilation in KFP v2 when a component or pipeline is called with an argument that evaluates to `None`, or an unsupported type, where a specific primitive type or a `PipelineParam` is expected by the `kfp-pipeline-spec` schema.fixEnsure all pipeline and component input arguments are explicitly set to a supported type (string, int, float, bool, dict, list, or PipelineParam) and do not default to or receive `None` unless specifically handled. Check pipeline function definitions and component calls for missing or unset parameters.
Warnings
- breaking The pipeline specification format underwent significant changes between Kubeflow Pipelines v1 and v2. `kfp-pipeline-spec` is designed for KFP v2 and is not compatible with pipeline definitions or compilers from KFP v1.
- gotcha `kfp-pipeline-spec` is primarily a definitions library for the KFP v2 pipeline schema. Most pipeline authors will interact with this schema indirectly through the `kfp` SDK's `kfp.dsl` and `kfp.compiler` modules, rather than directly constructing protobuf objects from `kfp_pipeline_spec`.
- gotcha The KFP ecosystem consists of several related Python packages (`kfp`, `kfp-pipeline-spec`, `kfp-server-api`, `kfp-kubernetes`). It's a common mistake to confuse which package provides specific classes or functionalities. For example, the `Compiler` is in `kfp`, while `PipelineSpec` definition is in `kfp-pipeline-spec`.
Install
-
pip install kfp-pipeline-spec==2.16.0
Imports
- PipelineSpec
from kfp.v2.compiler.pipeline_spec_pb2 import PipelineSpec
from kfp_pipeline_spec.pipeline_spec_pb2 import PipelineSpec
- ContainerSpec
from kfp_pipeline_spec.pipeline_spec_pb2 import ContainerSpec
Quickstart
import kfp_pipeline_spec.pipeline_spec_pb2 as pb
from google.protobuf import json_format
# Create a minimal KFP PipelineSpec object directly using the protobuf definitions
pipeline_spec = pb.PipelineSpec(
pipeline_info=pb.PipelineInfo(name="my-direct-pipeline"),
root=pb.PipelineTaskSpec(
executor_label="my-executor",
inputs=pb.TaskInputsSpec(),
outputs=pb.TaskOutputsSpec(),
),
components={
"my-executor": pb.ComponentSpec(
executor_label="my-executor",
input_definitions=pb.ComponentInputsSpec(),
output_definitions=pb.ComponentOutputsSpec(),
implementation=pb.ComponentSpec.ContainerImplementation(
container=pb.ContainerSpec(
image="python:3.9-slim",
command=["python", "-c", "print('Hello from kfp-pipeline-spec!')"]
)
)
)
}
)
# Serialize the PipelineSpec to JSON (as it would be in a compiled YAML file)
json_output = json_format.MessageToJson(pipeline_spec, indent=2)
print(json_output)
# To verify it's a valid spec object
assert isinstance(pipeline_spec, pb.PipelineSpec)
print(f"Pipeline name: {pipeline_spec.pipeline_info.name}")