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)
Validate all your Customer IAM Policies against AWS Access Analyzer - Policy Validation

✅ Access Analyzer - Batch Policy Validator This script will analyze using AWS Access Analyzer - Policy Validation all your account customer managed IA

Victor GRENU 41 Dec 12, 2022
A cross-platform script to book first available time for getting a passport in Sweden - Ett skript som automatiskt bokar pass hos polisen

Automatic passport booker - Boka pass automatiskt hos Svenska polisen A cross-platform script to book first available time for getting a passport in S

Elias Floreteng 14 Oct 17, 2022
This bot is created by AJTimePyro and It accepts direct downloading url & then return file as telegram file.

URL Uploader Bot This is the source code of URL Uploader Bot. And the developer of this bot is AJTimePyro, His Telegram Channel & Group. You can use t

Abhijeet 23 Nov 13, 2022
Data Platform com AWS CDK

Welcome to your CDK Python project! This is a blank project for Python development with CDK. The cdk.json file tells the CDK Toolkit how to execute yo

Andre Sionek 8 Jul 02, 2022
Simple Discord bot for snekbox (sandboxed Python code execution), self-host or use a global instance

snakeboxed Simple Discord bot for snekbox (sandboxed Python code execution), self-host or use a global instance

0 Jun 25, 2022
Python Markov Chain chatbot running on Telegram

Hanasubot Hanasubot (Japanese 話すボット, talking bot) is a Python chatbot running on Telegram. The bot is based on Markov Chains so it can learn your word

12 Dec 27, 2022
Automate saving your Discover Weekly Playlist using Python.

SpotWeekly Automate saving your Discover Weekly Playlist using Python. Made with 3 and FastAPI. The saved playlist link is sent to my discord server

shourya 6 Jan 03, 2022
Migrate BiliBili watched anime to Bangumi

说明 之前为了将B站看过的动画迁移到bangumi写的, 本来只是自己用, 但公开可能对其他人会有帮助. 仓库最近无法维护, 程序有很多缺点, 欢迎 PR 和 Contributors 使用说明 Python版本要求:Python 3.8+ 使用前安装依赖包: pip install -r requ

51 Sep 08, 2022
✨ 🐍 Python SDK for StarkNet.

✨ 🐍 starknet.py StarkNet SDK for Python 📘 Documentation Installation Quickstart Guide API Installation To install this package run pip install stark

Software Mansion 158 Jan 04, 2023
QR-Code-Grabber - A python script that allows a person to create a qr code token grabber

Qr Code Grabber Description Un script python qui permet a une personne de creer

5 Jun 28, 2022
This checks that your credit card is valid or not

Credit_card_Validator This checks that your credit card is valid or not. Where is the app ? main.exe is the application to run and main.py is the file

Ritik Ranjan 1 Dec 21, 2021
Analytics platform for Telegram Channels

Tele-Report Analytics platform for Telegram Channels 🚧 👷 Getting Started 1- Install redis and postgreSQL (it would be more generic in future, like u

2 Oct 11, 2022
Weather Tracker, made with Python using Open Weather API

Weather Tracker Weather Tracker, made with Python using Open Weather API

Sahil Kumar 1 Feb 07, 2022
A simple Discord bot that can fetch definitions and post them in chat.

A simple Discord bot that can fetch definitions and post them in chat. If you are connected to a voice channel, the bot will also read out the definition to you.

Tycho Bellers 4 Sep 29, 2022
PepeSniper is an open-source Discord Nitro auto claimer/redeemer made in python.

PepeSniper is an open-source Discord Nitro auto claimer made in python. It sure as hell is not the fastest sniper out there but it gets the job done in a timely and stable manner. It also supports ho

Unknown User 1 Dec 22, 2021
Discord.py Bot Series With Python

Discord.py Bot Series YouTube Playlist: https://www.youtube.com/playlist?list=PL9nZZVP3OGOAx2S75YdBkrIbVpiSL5oc5 Installation pip install -r requireme

Step 1 Dec 17, 2021
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

1 Feb 03, 2022
A discord bot providing notifications of player activity on a minecraft server.

tos-alert A discord bot providing notifications of player activity on a minecraft server. Setup By default the app does not launch and will crash with

1 Jul 22, 2022
Python client for Vektonn

Python client for Vektonn Installation Install the latest version: $ pip install vektonn Install specific version: $ pip install vektonn==1.2.3 Upgrad

Vektonn 16 Dec 09, 2022
Python3 program to control Elgato Ring Light on your local network without Elgato's Control Center software

Elgato Light Controller I'm really happy with my Elgato Key Light from an illumination perspective. However, their control software has been glitchy f

Jeff Tarr 14 Nov 16, 2022