Creating a client

class github2.client.Github(username=None, api_token=None, requests_per_second=None, access_token=None, cache=None, proxy_host=None, proxy_port=8080, github_url=None)[source]

Interface to GitHub’s API v2.

project_for_user_repo(user, repo)[source]

Return GitHub identifier for a user’s repository.

  • user (str) – repository owner
  • repo (str) – repository name


There are three ways to authenticate to the GitHub API. If you want to use your username and API token, use:

>>> from github2.client import Github
>>> github = Github(username="ask", api_token=".......")

If you authenticated to GitHub using their OAuth service, pass in the OAuth access token:

>>> github = Github(access_token="........")


You can retrieve the user data for an OAuth authenticated user with"").

Or for an unauthenticated connection:

>>> github = Github()

The package supports caching of GitHub responses by adding a cache keyword during setup:

>>> github = Github(username="ask", api_token=".......", cache="cache_dir")

API calls are limited by to 1 per second by default. To have the Github client enforce this and avoid rate limit errors, pass requests_per_second in:

>>> from github2.client import Github
>>> github = Github(username="ask", api_token=".......",
...                 requests_per_second=1)

By default, httplib2 0.7.4 will use the proxies set in the http_proxy andr https_proxy environment variables. This means that well configured systems shouldn’t need any manual configuration for proxy support.

If you wish to manually configure a HTTP proxy you can pass in the proxy_host and proxy_port settings to enable it. The default for proxy_port, if not given, is 8080:

>>> from github2.client import Github
>>> github = Github(username="ask", api_token=".......",
...                 proxy_host="", proxy_port=9000)

You may specify a GitHub Enterprise URL by passing in the github_url setting. If you do not specify github_url, requests will be made to

>>> from github2.client import Github
>>> github = Github(username="modocache", api_token=".......",
...                 github_url="")

Table Of Contents

Previous topic

API documentation

Next topic


This Page