Skip to main content

Python wrapper for the Buildkite API

Project description

PyBuildkite

Build status Coverage Status PyPI most recent version PyPI downloads

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybuildkite-1.2.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybuildkite-1.2.2-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file pybuildkite-1.2.2.tar.gz.

File metadata

  • Download URL: pybuildkite-1.2.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.2

File hashes

Hashes for pybuildkite-1.2.2.tar.gz
Algorithm Hash digest
SHA256 338ff4edd3e32e8f32480fe92d3bedd485052ed0c4bb09ddaa10dc1a9eed8006
MD5 952c9c84a65a99764cfdb848c307e1df
BLAKE2b-256 af0ffdf42241e10cd09e176ff88a851b158950cac6a6eb3cad6d282cbeaea32a

See more details on using hashes here.

File details

Details for the file pybuildkite-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: pybuildkite-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.2

File hashes

Hashes for pybuildkite-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9079f2d2ec6f429dd3b66f4e3cee26a364b408af25c92cee9516abad6938219a
MD5 8aede8d7bd6ec61bfa59b409f554e088
BLAKE2b-256 2bd6b9ecc4e10274f996114df1b9fdb19b780ab7d8ade114a1f9ff23f1c975ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page