Services

Github class is a glue to all of them and the recommended option to start

Overview

You can access to the API requests through the different services.

If you take a look at github API v3 documentation, you’ll see a few sections in the sidebar.

pygithub3 has one service per each section of request-related

For example:

repos => services.repos.repo
    collaborators => services.repos.collaborators
    commits => services.repos.commits
    ....

Each service has the functions to throw the API requests and is isolated from the rest.

Config each service

Each service can be configurated with some variables (behind the scenes, each service has her client which is configurated with this variables).

Note

Also you can configure Github as a service

class pygithub3.services.base.Service(**config)

You can configure each service with this keyword variables:

Parameters:
  • login (str) – Username to authenticate
  • password (str) – Username to authenticate
  • user (str) – Default username in requests
  • repo (str) – Default repository in requests
  • token (str) – Token to OAuth
  • per_page (int) – Items in each page of multiple returns
  • base_url (str) – To support another github-related API (untested)
  • verbose (stream) – Stream to write debug logs
  • float (timeout) – Timeout for requests

You can configure the authentication with BasicAuthentication (login and password) and with OAuth ( token). If you include login, password and token in config; Oauth has precedence

Some API requests need user and/or repo arguments (e.g repos service). You can configure the default value here to avoid repeating

Some API requests return multiple resources with pagination. You can configure how many items has each page.

You can configure verbose logging like requests library

set_credentials(login, password)

Set Basic Authentication

Parameters:
  • login (str) – Username to authenticate
  • password (str) – Username to authenticate
set_repo(repo)

Set repository

Parameters:repo (str) – Default repository in requests
set_token(token)

Set OAuth token

Parameters:token (str) – Token to OAuth
set_user(user)

Set user

Parameters:user (str) – Default username in requests

MimeTypes

Some services supports mimetypes

With them the Resources will have body, body_text, body_html attributes or all of them.

class pygithub3.services.base.MimeTypeMixin

Mimetype support to Services

Adds 4 public functions to service:

set_full()

Resource will have body, body_text and body_html attributes

set_html()

Resource will have body_html attribute

set_raw()

Resource will have body attribute

set_text()

Resource will have body_text attribute

Fast example:

from pygithub3 import Github

gh = Github()

gh.gists.comments.set_html()
comment = gh.gists.comments.list(1).all()[0]
print comment.body, comment.body_text, comment.body_html