Buildkite SDK for Python
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
- breaking As the SDK generates types directly from the Buildkite pipeline schema, major schema changes in Buildkite's platform can introduce breaking changes in the SDK's generated classes and methods. Consult the changelog for specific version upgrade details.
- gotcha The `buildkite-sdk` is specifically designed for *generating* Buildkite pipeline YAML or JSON for dynamic pipelines, not for direct interaction with the Buildkite API (e.g., fetching build statuses, creating builds). For direct API interaction, the `pybuildkite` library (a separate project) is typically used.
- gotcha The Buildkite SDK is currently considered a 'preview' feature. While functional, this status suggests that its API or behavior might be subject to change in future releases, and users are encouraged to report any issues via GitHub.
- gotcha The generated pipeline YAML/JSON from the `buildkite-sdk` is not directly sent to Buildkite by the SDK itself. It must be uploaded by a `buildkite-agent` running within a Buildkite build. This is typically done by piping the script's output: `python your_script.py | buildkite-agent pipeline upload`.
Install
-
pip install buildkite-sdk -
uv add buildkite-sdk
Imports
- Pipeline
from buildkite_sdk import Pipeline
Quickstart
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