Buildkite SDK for Python

0.10.0 · active · verified Tue Apr 14

The `buildkite-sdk` is an open-source, multi-language Software Development Kit (SDK) that simplifies scripting the generation of pipeline steps for dynamic Buildkite pipelines in native languages like Python. It consumes the Buildkite pipeline schema to provide type-safe programmatic pipeline creation and serialization to YAML or JSON. The current version is 0.10.0 and it maintains a synchronized release cadence across all supported languages (Python, JavaScript/TypeScript, Go, Ruby, C#).

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple Buildkite pipeline programmatically using the `buildkite-sdk`. It defines two command steps and then prints the resulting pipeline in YAML format. The output can then be uploaded to Buildkite via the `buildkite-agent pipeline upload` command.

from buildkite_sdk import Pipeline
from buildkite_sdk.schema import CommandStep

# Create a new pipeline
pipeline = Pipeline()

# Add a simple command step
pipeline.add_step(CommandStep(command="echo 'Hello from Buildkite SDK!'"))

# Add another step with more detail
pipeline.add_step(
    CommandStep(
        label=":python: Run Python Tests",
        command="pip install -r requirements.txt && pytest",
        agents={
            "queue": "default"
        }
    )
)

# Output the generated pipeline in YAML format
print(pipeline.to_yaml())

# To upload this to Buildkite, you would typically pipe the output:
# python your_script.py | buildkite-agent pipeline upload

view raw JSON →