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)
Google Sheets Python API v4

pygsheets - Google Spreadsheets Python API v4 A simple, intuitive library for google sheets which gets your work done. Features: Open, create, delete

Nithin Murali 1.4k Jan 08, 2023
PYAW allows you to call assembly from python

PYAW allows you to call assembly from python

2 Dec 13, 2021
Credit Card And SK Checker Written In Python

Credit Card And SK Checker Written In Python

Rimuru Tempest 57 Jan 08, 2023
A self-bot for discord, written in Python, which will send you notifications to your desktop if it detects an intruder on your discord server

A self-bot for discord, written in Python, which will send you notifications to your desktop if it detects an intruder on your discord server

LevPrav 1 Jan 11, 2022
Criando Lambda Functions para Ingerir Dados de APIs com AWS CDK

LIVE001 - AWS Lambda para Ingerir Dados de APIs Fazer o deploy de uma função lambda com infraestrutura como código Lambda vai numa API externa e extra

Andre Sionek 12 Nov 20, 2022
A powerfull Zee5 Downloader Bot With Permeneant Thumbnail Support 💯 With Love From NexonHex

Zᴇᴇ5 DL A ᴘᴏᴡᴇʀғᴜʟʟ Zᴇᴇ5 Dᴏᴡɴʟᴏᴀᴅᴇʀ Bᴏᴛ Wɪᴛʜ Pᴇʀᴍᴇɴᴇᴀɴᴛ Tʜᴜᴍʙɴᴀɪʟ Sᴜᴘᴘᴏʀᴛ 💯 Wɪᴛʜ Lᴏᴠᴇ Fʀᴏᴍ NᴇxᴏɴHᴇx Wʜᴀᴛ Cᴀɴ I Dᴏ ? • ɪ ᴄᴀɴ Uᴘʟᴏᴀᴅ ᴀs ғɪʟᴇ/ᴠɪᴅᴇᴏ ғʀᴏᴍ

Psycharmers 4 Jan 19, 2022
ThetaGang is an IBKR bot for collecting money

💬 Join the Matrix chat, we can get money together. Θ ThetaGang Θ Beat the capitalists at their own game with ThetaGang 📈 ThetaGang is an IBKR tradin

Brenden Matthews 1.5k Jan 08, 2023
Yes, it's true :revolving_hearts: This repository has 301 stars.

Yes, it's true! Inspired by a similar repository from @RealPeha, but implemented using a webhook on AWS Lambda and API Gateway, so it's serv

510 Dec 28, 2022
This is a discord token generator(requests) which works and makes 200 tokens per minute

Discord Email verified token generator Creates email verified discord accounts (unlocked) Report Bug · Discord server Features Profile pictures and na

131 Dec 10, 2022
Modular Python-based Twitch bot optimized for customizability and ease of use.

rasbot Modular Python-based Twitch bot optimized for customizability and ease of use. rasbot is a Python-based Twitch bot that runs on your Twitch acc

raspy 9 Dec 14, 2022
HackerNews and Reddit in one placce

EDIT: this project is 3.5 years old. I found it sad it's just laying around, so I did some minimal fixes and deployed it. Hope you enjoy! (PR's welcom

Hugo Montenegro 1 Nov 13, 2021
WhatsApp API Python ChatBot

WhatsApp Api Python - Esta documentação tem como objetivo exemplificar o uso do Moorse Whatsapp API na linguagem Python.

Douglas Alves 2 Jan 06, 2022
A Python Module That Uses ANN To Predict A Stocks Price And Also Provides Accurate Technical Analysis With Many High Potential Implementations!

Stox ⚡ A Python Module For The Stock Market ⚡ A Module to predict the "close price" for the next day and give "technical analysis". It uses a Neural N

Dopevog 31 Dec 16, 2022
Home Assistant Hilo Integration via HACS

BETA This is a beta release. There will be some bugs, issues, etc. Please bear with us and open issues in the repo. Hilo Hilo integration for Home Ass

66 Dec 23, 2022
Updater for PGCG (Paradox Game Converters Group) converters written in Python.

Updater Updater for PGCG (Paradox Game Converters Group) converters written in Python. Needs to be put inside an "Updater" directory in the root conve

Paradox Game Converters 2 Jan 10, 2022
Represents a Lavalink client used to manage nodes and connections.

lavaplayer Represents a Lavalink client used to manage nodes and connections. setup pip install lavaplayer setup lavalink you need to java 11* LTS or

HazemMeqdad 37 Nov 21, 2022
A telegram bot which can show you the status of telegram bot

BotStatus-Ts-Bot An open source telegram Bot Status bot For demo you can check here The status is updated in every 1 hour About Bot This is a Bot stat

Ts_Bots 8 Nov 17, 2022
How to make a QR Code of your own in python

QR CODE Bilgilendirme! " pip install qrcode pillow " kurmalısınız.

Aktali 1 Dec 24, 2021
Brute Force Attack On Facebook Accounts

Brute Force Attack On Facebook Accounts For Install: pkg install update && pkg upgrade -y pkg install python pip install requests pip install mechani

MK X Shaon 1 Oct 30, 2021
Brute force instagram account / actonetor, 2021

Brute force instagram account / actonetor, 2021

actonetor 6 Nov 16, 2022