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)
QuickStart specific rules for cfn-python-lint

AWS Quick Start cfn-lint rules This repo provides CloudFormation linting rules specific to AWS Quick Start guidelines, for more information see the Co

AWS Quick Start 12 Jul 30, 2022
A Telegram Bin Checker Bot made with python for check Bin valid or Invalid. 💳

Bin Checker Bot A Telegram Bin Checker Bot made with python for check Bin valid or Invalid. 📌 Deploy On Heroku 🏷 Environment Variables API_ID - Your

Chamindu Denuwan 20 Dec 10, 2022
OpenQuake's Engine for Seismic Hazard and Risk Analysis

OpenQuake Engine The OpenQuake Engine is an open source application that allows users to compute seismic hazard and seismic risk of earthquakes on a g

Global Earthquake Model 281 Dec 21, 2022
This is a small package to interact with the OpenLigaDB API.

OpenLigaDB This is a small package to interact with the OpenLigaDB API. Installation Run the following to install: pip install openligadb Usage from o

1 Dec 31, 2021
A user reconnaisance tool that extracts a target's information from Instagram, DockerHub & Github.

A user reconnaisance tool that extracts a target's information from Instagram, DockerHub & Github. Also searches for matching usernames on Github.

Richard Mwewa 127 Dec 22, 2022
:electric_plug: Generating short urls with python has never been easier

pyshorteners A simple URL shortening API wrapper Python library. Installing pip install pyshorteners Documentation https://pyshorteners.readthedocs.i

Ellison 351 Jan 03, 2023
Implementation of the paper 'Sentence Bottleneck Autoencoders from Transformer Language Models'

Introduction This repository contains the code for the paper Sentence Bottleneck Autoencoders from Transformer Language Models by Ivan Montero, Nikola

Ivan Montero 14 Dec 28, 2022
Discord-RAID-Tool - Hacks/tools

How to use Python must be installed run install-config If you dont have python installed, download python 3.7.6 and make sure you click on the 'ADD TO

1 Jan 01, 2022
A Telegram Message Manager Bot by @AbirHasan2005

Messages-Manager-Bot A Telegram Message Manager Bot by @AbirHasan2005. This Bot can delete specific type of messages from Group. I specially use for @

Abir Hasan 32 Nov 12, 2022
The official Pushy SDK for Python apps.

pushy-python The official Pushy SDK for Python apps. Pushy is the most reliable push notification gateway, perfect for real-time, mission-critical app

Pushy 1 Dec 21, 2021
An open-source Discord Nuker can be used as a self-bot or a regular bot.

How to use Double click avery.exe, and follow the prompts Features Important! Make sure to use [9] (Scrape Info) before using these, or some things ma

Exortions 3 Jul 03, 2022
Hack WhatsApp Account Easily(Android)

X-Whatsapp Hack WhatsApp Account Easily(Android) HOW TO RUN 👇 (Termux) pkg update && pkg upgrade pkg install python pkg install git git clone https:/

KiLL3R_xRO 72 Dec 21, 2022
IACR Events Scraper

IACR Events Scraper This scrapes https://iacr.org/events/ and exports it as a calendar file. I host a version of this for myself under https://arrrr.c

Karolin Varner 6 May 28, 2022
Best Buy Bot used to add products to cart for purchase.

To Install the Best Buy Bot These instructions are for Mac users only. Clone this Repo to your machine. BestBuyBot Open in VScode. Is Python installed

Robert Estrella 1 Dec 11, 2021
b2blaze

b2blaze Welcome to the b2blaze library for Python. Backblaze B2 provides the cheapest cloud object storage and transfer available on the internet. Com

George Sibble 603 Jan 03, 2023
The official Python library for the Plutto API

Plutto Ruby SDK This library will help you easily integrate Plutto API to your software, making your developer life a little bit more enjoyable. Insta

Plutto 3 Nov 23, 2021
A Rich renderable for viewing Multiple Sequence Alignments in the terminal.

rich-msa A simple module to render colorful Multiple Sequence Alignment with rich in the terminal. 🔧 Installing Install the rich-msa package directly

Martin Larralde 64 Dec 04, 2022
YouTube bot, this is just my introduction to api and requests, this isn't intended on being an actual view bot.

YouTube bot, this is just my introduction to api and requests, this isn't intended on being an actual view bot.

Aran 2 Jul 25, 2022
Simple integrate of API udemy.com with python

Pyudemy Simple integrate of API udemy.com with python Quick start $ pip install pyudemy or $ python setup.py install Authentication To make any calls

Hudson Brendon 30 Jan 02, 2023
Unofficial calendar integration with Gradescope

Gradescope-Calendar This script scrapes your Gradescope account for courses and assignment details. Assignment details currently can be transferred to

6 May 06, 2022