Python wrapper for the Buildkite API
Project description
PyBuildkite
A Python library and client for the Buildkite API.
Usage
To get the package, execute:
pip install pybuildkite
Then set up an instance of the Buildkite object, set you access token, and make any available requests.
from pybuildkite.buildkite import Buildkite, BuildState
buildkite = Buildkite()
buildkite.set_access_token('YOUR_API_ACCESS_TOKEN_HERE')
# Get all info about particular org
org = buildkite.organizations().get_org('my-org')
# Get all running and scheduled builds for a particular pipeline
builds = buildkite.builds().list_all_for_pipeline('my-org', 'my-pipeline', states=[BuildState.RUNNING, BuildState.SCHEDULED])
# Create a build
buildkite.builds().create_build('my-org', 'my-pipeline', 'COMMITSHA', 'master',
clean_checkout=True, message="My First Build!")
Pagination
Buildkite offers pagination for endpoints that return a lot of data. By default this wrapper return 100
objects. However, any request that may contain more than that offers a pagination option.
When with_pagination=True
, we return a response object with properties that may have next_page
, last_page
, previous_page
, or first_page
depending on what page you're on.
builds_response = buildkite.builds().list_all(page=1, with_pagination=True)
# Keep looping until next_page is not populated
while builds_response.next_page:
builds_response = buildkite.builds().list_all(page=builds_response.next_page, with_pagination=True)
Artifacts
Artifacts can be downloaded as binary data. The following example loads the artifact into memory as Python bytes and then writes them to disc:
artifacts = buildkite.artifacts()
artifact = artifacts.download_artifact("org_slug", "pipe_slug", "build_no", 123, "artifact")
with open('artifact.bin', 'b') as f:
f.write(artifact)
Large artifacts should be streamed as chunks of bytes to limit the memory consumption:
stream = artifacts.download_artifact("org_slug", "pipe_slug", "build_no", 123, "artifact", as_stream=True)
with open('artifact.bin', 'b') as f:
for chunk in stream:
f.write(chunk)
A unicode text artifact can be turned into a string easily:
text = str(artifact)
License
This library is distributed under the BSD-style license found in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pybuildkite-1.2.4.tar.gz
.
File metadata
- Download URL: pybuildkite-1.2.4.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c1fe9417b723035f757eee7a8749df351ad62da5372157f378b1fa99c0aa28c |
|
MD5 | 5f2d37a585adcb402cfd7aa28c403e2b |
|
BLAKE2b-256 | a8d56c9003e5e71b7ffb49c9a94eaa146c7854bd0af7e65a4baea7e859ca9505 |
File details
Details for the file pybuildkite-1.2.4-py3-none-any.whl
.
File metadata
- Download URL: pybuildkite-1.2.4-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 675f548fdbd58c356f5463323528dedaa3bff66414190fe2b8efa11f6123d7d0 |
|
MD5 | 0b1573f276656c231aa6f199f2b677a7 |
|
BLAKE2b-256 | 956f2aefa734c6ed775a2bf8311e6c6cc99cd00e1b4a6356bb1646219881e8ef |