Skip to main content

CircleCI API written in python

Project description

pycci

Simple python client for the CircleCI API

Installation

pip install pycci

Usage

Example usage can be found in the examples directory

Configuration

Before using the api you'll need to generate a circleci api token, and initialize the package with the key and the name of your organization.

from pycci import Config
Config.initialize('Your Org', 'Your Key')

If you want to store this configuration so you don't have to re-config everytime, pass in the store param

Config.initialize('Your Org', 'Your Key', store=True)

Models

Project

from pycci import Project
project = Project('Project Name')
pipelines = project.get_pipelines(num=100) # default is 20 to limit api calls for testing

Pipeline/Workflow/Job/Test

These models can all be fetched from circle CI following the project

from pycci import Pipeline, Workflow, Job, Test

pipelines = project.get_pipelines(num=100)
pipeline = pipelines[0]

workflows = pipeline.get_workflows(failed_only=True) # Get only failed workflows, False by default
workflow = workflows[0]

jobs = workflow.get_jobs(type='type of job', failed_only=True) # type is a String, the JOBTYPE enum has some values to use
job = jobs[0]

tests = job.get_tests(failed_only=True)

All of the data for the objects is stored in a dictionary under the data attribute.

API

All model instances are initialized with an api object instance that is accessible under the api attribute

project_api = project.api
pipeline_api = pipeline.api
workflow_api = workflow.api
job_api = job.api
# Test has no api

The api objects can also be created directly

from pycci import ProjectApi, PipelineApi, WorkflowApi, JobApi, JOBTYPE

project_api = ProjectApi('Project name')
result = project_api.get_pipelines(page_token=None)
next_page_token = result['next_page_token']
pipelines = result['items']

pipeline_api = PipelineApi('Pipeline id')
result = pipeline_api.get_workflows(failed_only=True, page_token=None)
next_page_token = result['next_page_token']
workflows = result['items']

workflow_api = WorkflowApi('Workflow id')
result = workflow_api.get_jobs(type=JOBTYPE.BACKEND, failed_only=True, page_token=None)
next_page_token = result['next_page_token']
jobs = result['items']

job_api = JobApi('Job id', 'Job Number', 'Project Slug')
# project slug looks like gh/org/project where gh is your version control
result = job_api.get_tests(failed_only=True, page_token=None)
next_page_token = result['next_page_token']
tests = result['items']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycci-1.0.0.tar.gz (3.9 kB view hashes)

Uploaded Source

Built Distribution

pycci-1.0.0-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page