Kubeflow Pipelines Server API

2.16.0 · active · verified Fri Apr 10

The `kfp-server-api` library provides a Python client for interacting directly with the Kubeflow Pipelines (KFP) v2 server API. It offers low-level access to KFP resources like pipelines, runs, and experiments, suitable for advanced integrations or custom automation. It is part of the KFP SDK v2 ecosystem, currently at version 2.16.0, and typically released in lockstep with the main `kfp` SDK.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `kfp-server-api` client, configure its host, and make a basic call to list pipelines. It assumes KFP is running and accessible at the specified host. For production deployments, robust authentication (e.g., OAuth2, Bearer tokens from service accounts) would be required, which needs to be configured in the `Configuration` object.

import os
from kfp_server_api import Configuration, ApiClient
from kfp_server_api.api.pipeline_service_api import PipelineServiceApi

# Replace with your KFP API endpoint. E.g., 'http://localhost:8080/pipeline'
# or 'https://<your-kfp-host>/pipeline'
KFP_HOST = os.environ.get('KFP_SERVER_API_HOST', 'http://localhost:8080')

# Configure API key authorization: Bearer
# For most KFP deployments, you might need a service account token or session cookie.
# Example for no auth or basic local setup:
configuration = Configuration(host=KFP_HOST)

# For token-based auth (e.g., from a service account or user session):
# KFP_API_TOKEN = os.environ.get('KFP_SERVER_API_TOKEN')
# if KFP_API_TOKEN:
#     configuration.access_token = KFP_API_TOKEN

# Create an API client
with ApiClient(configuration) as api_client:
    # Create an instance of the PipelineServiceApi
    pipeline_api = PipelineServiceApi(api_client)

    try:
        # List pipelines (requires appropriate authentication and permissions)
        list_response = pipeline_api.list_pipelines()
        print(f"Successfully connected to KFP API host: {KFP_HOST}")
        print(f"Found {len(list_response.pipelines or [])} pipelines.")
        for p in (list_response.pipelines or []):
            print(f"  - {p.display_name} (ID: {p.pipeline_id})")
    except Exception as e:
        print(f"Error connecting to KFP API or listing pipelines: {e}")
        print("Make sure KFP_SERVER_API_HOST is correctly set and you have necessary authentication.")

view raw JSON →