Registry / ai-ml / kubeflow

kubeflow

JSON →
library0.4.0pypypi✓ verified 80d ago

The Kubeflow Python SDK (current version 0.4.0) provides a client library to programmatically manage machine learning workloads and interact with various Kubeflow APIs. It allows users to define, create, monitor, and delete training jobs (e.g., PyTorchJob, TFJob), hyperparameter optimization jobs (Katib), and other ML-related resources directly from Python. Releases are frequent, typically focusing on new features and bug fixes across minor versions.

pip install kubeflow
INSTALL
IMPORT
SIG · KUBEFLOW
K
kubeflow
ai-mlpythonv0.4.0
Install
9.5s avg
Import
Disk
128MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 133.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 9.5s · import 0.000s · 135MB
128MB installed
● package 128MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TrainerClient
import kubeflow
from kubeflow import TrainerClient

This quickstart demonstrates how to create a simple PyTorch training job using the Kubeflow SDK's `TrainerClient`. It defines a `PyTorchJob` spec and submits it to a Kubeflow cluster. This code requires an active Kubeflow deployment and a properly configured `kubectl` context to run successfully.

import os from kubeflow.sdk.training import TrainerClient from kubeflow.sdk.training.api import TrainingJob from kubeflow.sdk.training.models import V1PyTorchJob, V1RunPolicy # NOTE: This example requires a running Kubeflow cluster and configured kubectl context. # It will create a PyTorch training job in the 'kubeflow' namespace. # Define your training job training_job = TrainingJob( api_version="kubeflow.org/v1", kind="PyTorchJob", metadata={ "name": os.environ.get('KF_JOB_NAME', 'my-pytorch-job'), "namespace": os.environ.get('KF_NAMESPACE', 'kubeflow') }, spec=V1PyTorchJob( pytorch_replica_specs={ "Worker": { "replicas": 1, "restartPolicy": "OnFailure", "template": { "spec": { "containers": [ { "name": "pytorch", "image": "pytorch/pytorch:1.9.0-cuda11.1-cudnn8-runtime", "command": ["python", "-c", "print('Hello Kubeflow!')"], } ] } }, } }, run_policy=V1RunPolicy(clean_pod_policy="All"), ), ) # Initialize the TrainerClient try: trainer_client = TrainerClient() # Create the training job on the Kubeflow cluster created_job = trainer_client.create_job(job=training_job) print(f"Job '{created_job.metadata.name}' created in namespace '{created_job.metadata.namespace}'.") # Wait for job completion (optional, can block) # trainer_client.wait_for_job_completion(name=created_job.metadata.name, namespace=created_job.metadata.namespace) # print(f"Job '{created_job.metadata.name}' completed.") # Get job status (optional) status = trainer_client.get_job_status(name=created_job.metadata.name, namespace=created_job.metadata.namespace) print(f"Job status: {status.state}") # Delete the job (optional, uncomment to enable) # trainer_client.delete_job(name=created_job.metadata.name, namespace=created_job.metadata.namespace) # print(f"Job '{created_job.metadata.name}' deleted.") except Exception as e: print(f"An error occurred: {e}") print("Ensure your kubectl context is correctly configured and pointing to a Kubeflow cluster.")
Debug
Known issues
breakingThe `PodTemplateOverrides` API for custom pod modifications in training jobs has been replaced by `RuntimePatches` starting from Kubeflow SDK v0.4.0.
fix
Migrate your training job definitions to use `RuntimePatches` instead of `PodTemplateOverrides` for advanced pod customization.
affects: 0.4.0 and later
gotchaThe Kubeflow SDK client interacts with a remote Kubeflow cluster. Your Python environment needs a configured `kubectl` context (e.g., ~/.kube/config) pointing to a running Kubeflow instance.
fix
Ensure `kubectl` is installed and configured to connect to your Kubeflow cluster. Verify connectivity with `kubectl get pods -n kubeflow`.
affects: All versions
gotchaThere can be compatibility issues between the Kubeflow SDK version and the version of Kubeflow deployed on your cluster, especially with CRD (Custom Resource Definition) versions for training operators (e.g., PyTorchJob, TFJob).
fix
Check the official Kubeflow documentation for recommended SDK versions compatible with your cluster's Kubeflow deployment. Upgrade/downgrade the SDK or your cluster components as needed.
affects: All versions
gotchaThe `TrainerClient` and `OptimizerClient` are distinct and manage different components of Kubeflow. Ensure you are importing and using the correct client for training jobs (`TrainerClient`) versus hyperparameter optimization jobs (`OptimizerClient`).
fix
Use `from kubeflow.sdk.training import TrainerClient` for training jobs and `from kubeflow.sdk.optimizer import OptimizerClient` for Katib (HPO) jobs.
affects: All versions
Upgrade
Version history
0.4.0latest on PyPI · released Mar 20, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
kubeflow — pip install kubeflow · libregistry