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)
Listen to the radio station from your favorite broadcast

Latest news Listen to the radio station from your favorite broadcast MyCroft Radio Skill for testing and copy at docker skill About Play regional radi

1 Dec 22, 2021
Want to get your driver's license? Can't get a appointment because of COVID? Well I got a solution for you.

NJDMV-appoitment-alert Want to get your driver's license? Can't get a appointment because of COVID? Well I got a solution for you. We'll get you one i

Harris Spahic 3 Feb 04, 2022
Set of classes and tools to communicate with a Noso wallet using NosoP

NosoPy Set of classes and tools to communicate with a Noso wallet using NosoP(Noso Protocol). The data that can be retrieved consist of: Node informat

Noso Project 1 Jan 10, 2022
TESSARECT A Powerful Bot you'll ever need for anything

Tessarect TESSARECT A Powerful Bot you'll ever need for anything TESSARECT It is my First bot but very advanced and designed for all your needs , from

Prakarsh Prp 4 Aug 27, 2022
API para realizar parser de frases

NLP API Simple api to parse and apply some preprocessing steps in portuguses phrases (pt_BR) This api uses the great FastAPI and spaCy packages! Usage

⟠ Rodolfo De Nadai 1 Dec 28, 2021
A telegram bot that sends a meme a day, from reddit's top meme of the day

MemeBot A telegram bot that sends a meme a day, from reddit's top meme of the day You can use the bot either with an external scheduler (ex: pythonany

Michele Vitulli 1 Dec 13, 2021
Automation for grabbing keys from a Linux host. Useful during red team exercises to quickly help assess what access to a Linux host can lead to.

keygrabber Automation for grabbing keys from a Linux host. This can be helpful during red team exercises when you gain access to a Linux host and want

Cedric Owens 14 Sep 27, 2022
A GUI Weather Application written with Python

weather-box - A GUI Weather Application written with Python Made with ❤️ by Suresh Mishra

Suresh Mishra 2 Dec 18, 2021
Braje: a python based credit hacker tool. Hack unlimited RAJE LIKER app Credit

#ReCoded Evan Al Mahmud Irfan ✨ ථ BRAJE 1.0 AUTO LIKER, AUTO COMMENT AND AUTO FOLLOWER APP CREDIT HACKER TOOL About Braje: Braje is a python based cre

Evan Al Mahmud Irfan ථ 2 Dec 23, 2021
DIAL(Did I Alert Lambda?) is a centralised security misconfiguration detection framework which completely runs on AWS Managed services like AWS API Gateway, AWS Event Bridge & AWS Lambda

DIAL(Did I Alert Lambda?) is a centralised security misconfiguration detection framework which completely runs on AWS Managed services like AWS API Gateway, AWS Event Bridge & AWS Lambda

CRED 71 Dec 29, 2022
Cogs version of iso6.9 with the help of thatOneArchUser

iso6.9-cogs (debloated) This is a cogs version of iso6.9 by αrchιshα#5518. iso6.9 is a Discord bot written in Python and is used to make your Discord

Kamilla Youver 2 Jun 10, 2022
IOGen - An Open source discord token generator

_____ ____ _____ |_ _/ __ \ / ____| | || | | | |

0xVichy#1234 85 Nov 03, 2022
Discord Webhook Proxy for Roblox payloads.

RoProxy A Discord webhook proxy passthrough for roblox. Setup Your port and endpoint are in the config.json, make sure both app.py and config.json are

PythonSerious 2 Nov 05, 2021
A fully decentralized protocol for private transactions FAST snipe BUY token on LUANCH after add LIQUIDITY

TORNADO CASH Pancakeswap Sniper BOT 2022-V1 (MAC WINDOWS ANDROID LINUX) ⭐️ A fully decentralized protocol for private and safe transactions ⭐️ AUTO DO

Crypto Trader 2 Jan 06, 2022
A bot which provides online/offline and player status for Thicc SMP, using Replit.

AlynaaStatus A bot which provides online/offline and player status for Thicc SMP. Currently being hosted on Replit. How to use? Create a repl on Repli

QuanTrieuPCYT 8 Dec 15, 2022
An advanced api client for python botters.

[ALPHA] pybotters An advanced api client for python botters. 📌 Description pybottersは仮想通貨botter向けのPythonライブラリです。複数取引所に対応した非同期APIクライアントであり、bot開発により素晴ら

261 Dec 31, 2022
A GETTR API client written in Python.

GUTTR A GETTR client library written in Python. I rushed to get this out so it's a bit janky. Open an issue if something is broken or missing. Getting

Roger Johnston 13 Nov 23, 2022
Python client for the Echo Nest API

Pyechonest Tap into The Echo Nest's Musical Brain for the best music search, information, recommendations and remix tools on the web. Pyechonest is an

The Echo Nest 655 Dec 29, 2022
A pypi package that helps in generating discord bots.

A pypi package that helps in generating discord bots.

PineCode Corp 3 Nov 17, 2021
Find songs by lyrics.

LyricSearch Hi, welcome to LyricSearch - a simple (Yes), fast (Maybe), and powerful (Approach) lyric search engine. We support Three search methods to

Dicer_ 1 Dec 13, 2021