A Python library for the Buildkite API

Overview

PyBuildkite Build status Coverage Status

pypi pypi

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.

Comments
  • Replace query params in url with params in get

    Replace query params in url with params in get

    This replaces the previous implementation of manually calling encoding query params with urlencode with requests.get(url, params=params, ...).

    This moves the responsibility of encoding the query parameters to the requests library.

    Less responsibility is usually better! ;)

    opened by asheidan 6
  • Build Create, Update, and Delete functionality for numerous endpoints

    Build Create, Update, and Delete functionality for numerous endpoints

    Pipelines, Builds, Jobs, and Agents are all currently only using GET endpoints. We need full CRUD ability, adding POST, PUT, and DELETE functionality to these to make them feature complete would be great. Doesn't have to be all in one PR.

    hacktoberfest 
    opened by pyasi 6
  • Add optional team_uuids param

    Add optional team_uuids param

    Summary

    This adds team_uuids optional parameter to create_yaml_pipeline. For our organisation, teams are mandatory for pipeline creation, and when omitted will result in:

    {"message":"Validation Failed","errors":[{"field":"teams","code":"Please ensure at least one team is added to this pipeline","value":[]}]}
    
    opened by raven 5
  • Rework artifact download

    Rework artifact download

    This changes the way artifacts are downloaded:

    • Always returns bytes, not unicode text or parsed Json
    • Can return iterator of bytes chunks to stream artifact over HTTP

    Artifacts can be of arbitrary mime type, but currently they are always parsed as JSON, which fails for everything but JSON artifacts. Artifacts should be downloaded as bytes, where user code can than treat those bytes as desired, e.g.: json.loads(str(the_bytes)).

    The client.get method currently only returns either parsed JSON or unicode text, so this has to be touched as well. Encoding the retrieved bytes as unicode as a default for any non application/json mime type is quite a hard assumption, and even if type is text/* this could be encode in so many other ways. Again, user code can easily decode the bytes as required. So I think bytes is a good default return type for client.get if Accept is something other than application/json.

    Finally, since requests supports HTTP streaming, the artifact content can easily be streamed to user code as well (e.g. to write that to disk). With streaming, memory footprint stays low and independent of the size of the downloaded artifact.

    Artifact content can be consumed like:

    If artifact is unicode:

        artifact = artifacts.download_artifact("org_slug", "pipe_slug", "build_no", 123, "artifact")
        str(artifact)
    

    If artifact is json:

        artifact = artifacts.download_artifact("org_slug", "pipe_slug", "build_no", 123, "artifact")
        json.loads(str(artifact))
    

    Byte content of artifact:

        artifact = artifacts.download_artifact("org_slug", "pipe_slug", "build_no", 123, "artifact")
        with open('artifact.bin', 'b') as f:
          f.write(artifact)
    

    Streaming artifact:

        artifact = artifacts.download_artifact("org_slug", "pipe_slug", "build_no", 123, "artifact", as_stream=True)
        with open('artifact.bin', 'b') as f:
          for chunk in artifact:
            f.write(chunk)
    
    opened by EnricoMi 4
  • Create functionality for the 'meta' endpoint

    Create functionality for the 'meta' endpoint

    Create a new file and class to incorporate the meta API.

    • Create a new file called meta.py
    • Create a class called Meta
    • Return the Meta class from a method in buildkite.py
    • Write unit tests for the new code
    hacktoberfest beginner 
    opened by pyasi 3
  • Fix key and path issues in jobs and fix client response content type

    Fix key and path issues in jobs and fix client response content type

    Fixes several errors in Jobs class, in base_url, log, env, and fields for unblock. E.g., 500 Server Error: Internal Server Error for url: https://api.buildkite.com/v2//organizations/...

    opened by saraislet 3
  • Paginated results

    Paginated results

    Hi, I am trying to load all our builds via buildkite.builds().list_all This returns the first 100 results (as expected) but I can't figure out if there is a way to get the next 100 results.

    opened by jnewbigin 3
  • Create functionality for the Access Token API

    Create functionality for the Access Token API

    Create a new file and class to incorporate the Access Token API

    • Create a new file called access_token.py
    • Create a class called AccessToken
    • Return the AccessToken class from a method in buildkite.py
    • Write unit tests for the new code
    hacktoberfest beginner 
    opened by pyasi 2
  • Add support for updating pipelines

    Add support for updating pipelines

    The API provides support for updating a pipeline via PATCH: https://buildkite.com/docs/apis/rest-api/pipelines#update-a-pipeline

    This doesn't seem to be supported by the library yet (the base client also doesn't provide a PATCH method, so the only way to update a pipeline currently is using the rest API directly as far as I can tell).

    opened by bal2ag 2
  • Get builds with only one state fails

    Get builds with only one state fails

    Due to following line the state query param looks like passed instead of state=passed

    https://github.com/pyasi/pybuildkite/blob/59db85d18aed949970507b3af8f1fb30b1a18e52/pybuildkite/builds.py#L316

    pls add: state=+

    opened by Raz-B 2
  • New release

    New release

    It would be great if a new release could be issued, as I'm looking forward to using this improvement :pray: https://github.com/pyasi/pybuildkite/pull/82

    opened by mwgamble 1
  • [chore] disallow_untyped_defs

    [chore] disallow_untyped_defs

    My best attempt at partly addressing https://github.com/pyasi/pybuildkite/issues/48. This types all functions in pybuildkite/.

    I did this manually, so there might be some slightly incorrect types. Also, there are at least 3 # TODO: Bad Any. I most didn't feel like addressing. Sorry.

    Also, this will most likely conflict with https://github.com/pyasi/pybuildkite/pull/80.

    opened by jmelahman 1
  • add Metrics interface

    add Metrics interface

    Adds support for https://buildkite.com/docs/apis/agent-api/metrics.

    Screenshot_20220804_012452

    This API is somewhat different from the rest considering is use the agent token rather than the access token.

    Let me know if the high-level looks good and I can include some tests as well.

    Also, closes https://github.com/pyasi/pybuildkite/issues/72

    opened by jmelahman 1
  • Missing parameters for pipeline creation

    Missing parameters for pipeline creation

    The create_yaml_pipeline method is missing many parameters listed at https://buildkite.com/docs/apis/rest-api/pipelines#create-a-yaml-pipeline. These all need to be added. Alternatively, I would actually recommend just accepting kwargs for all parameters that don't need any further formatting. Then the Python package can be robust to changes to the Buildkite API with minimal maintenance. This comes at the cost of a more self-documenting Python API, but given the lack of activity on this repo I think it would be better to just point to the Buildkite documentation as the source of truth.

    opened by GMNGeoffrey 7
  • Add functionality to use the Add a Webhook API for Pipelines

    Add functionality to use the Add a Webhook API for Pipelines

    Create a method for the Add a Webhook functionality

    • Create a new method in pipelines.py to use the endpoint described above
    • Write unit tests for the new code
    hacktoberfest 
    opened by pyasi 0
  • Add Archive functionality to the Pipelines class

    Add Archive functionality to the Pipelines class

    Create methods for the Archive and Unarchive functionality

    • Create new methods in pipelines.py to use the endpoints described above
    • Write unit tests for the new code
    hacktoberfest 
    opened by pyasi 0
Releases(v1.2.1)
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Harun Mbaabu Mwenda 46 Sep 1, 2022
Python API wrapper library for Convex Value API

convex-value-python Python API wrapper library for Convex Value API. Further Links: Convex Value homepage @ConvexValue on Twitter JB on Twitter Authen

Aaron DeVera 2 May 11, 2022
This an API wrapper library for the OpenSea API written in Python 3.

OpenSea NFT API Python 3 wrapper This an API wrapper library for the OpenSea API written in Python 3. The library provides a simplified interface to f

Attila Tóth 159 Dec 26, 2022
Aio-binance-library - Async library for connecting to the Binance API on Python

aio-binance-library Async library for connecting to the Binance API on Python Th

GRinvest 10 Nov 21, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
WhatsApp Api Python - This documentation aims to exemplify the use of Moorse Whatsapp API in Python

WhatsApp API Python ChatBot Este repositório contém uma aplicação que se utiliza

Moorse.io 3 Jan 8, 2022
Official python API for Phish.AI public and private API to detect zero-day phishing websites

phish-ai-api Summary Official python API for Phish.AI public and private API to detect zero-day phishing websites How it Works (TLDR) Essentially we h

Phish.AI 168 May 17, 2022
Python API wrapper around Trello's API

A wrapper around the Trello API written in Python. Each Trello object is represented by a corresponding Python object. The attributes of these objects

Richard Kolkovich 904 Jan 2, 2023
A python to scratch API connector. Can fetch data from the API and send it back in cloud variables.

Scratch2py Scratch2py or S2py is a easy to use, versatile tool to communicate with the Scratch API Based of scratchclient by Raihan142857 Installation

null 20 Jun 18, 2022
Async ready API wrapper for Revolt API written in Python.

Mutiny Async ready API wrapper for Revolt API written in Python. Installation Python 3.9 or higher is required To install the library, you can just ru

null 16 Mar 29, 2022
🚀 An asynchronous python API wrapper meant to replace discord.py - Snappy discord api wrapper written with aiohttp & websockets

Pincer An asynchronous python API wrapper meant to replace discord.py ❗ The package is currently within the planning phase ?? Links |Join the discord

Pincer 125 Dec 26, 2022
wyscoutapi is an extremely basic API client for the Wyscout API (v2 & v3) for Python

wyscoutapi wyscoutapi is an extremely basic API client for the Wyscout API (v2 & v3). Usage Install with pip install wyscoutapi. To connect to the Wys

Ben Torvaney 11 Nov 22, 2022
A Python API wrapper for the Twitter API!

PyTweet PyTweet is an api wrapper made for twitter using twitter's api version 2! Installation Windows py3 -m pip install PyTweet Linux python -m pip

TheFarGG 1 Nov 19, 2022
A new coin listing alert bot using Python, Flask, MongoDB, Telegram API and Binance API

Bzzmans New Coin Listing Detection Bot Architecture About Project Work in progress. This bot basically gets new coin listings from Binance using Binan

Eyüp Barlas 21 May 31, 2022
YARSAW is an Async Python API Wrapper for the Random Stuff API.

Yet Another Random Stuff API Wrapper - YARSAW YARSAW is an Async Python API Wrapper for the Random Stuff API. This module makes it simpler for you to

Bruce 6 Mar 27, 2022
Python API Client for Twitter API v2

?? Python Client For Twitter API v2 ?? Why Twitter Stream ? Twitter-Stream.py a python API client for Twitter API v2 now supports FilteredStream, Samp

Twitivity 31 Nov 19, 2022
EpikCord.py - This is an API Wrapper for Discord's API for Python

EpikCord.py - This is an API Wrapper for Discord's API for Python! We've decided not to fork discord.py and start completely from scratch for a new, better structuring system!

EpikHost 28 Oct 10, 2022
A simple Python API wrapper for Cloudflare Stream's API.

python-cloudflare-stream A basic Python API wrapper for working with Cloudflare Stream. Arbington.com started off using Cloudflare Stream. We used the

Arbington 3 Sep 8, 2022