Main class: Github

class github.MainClass.Github(login_or_token=None, password=None, base_url='https://api.github.com', timeout=10, client_id=None, client_secret=None, user_agent='PyGithub/Python', per_page=30, api_preview=False)

This is the main class you instanciate to access the Github API v3. Optional parameters allow different authentication methods.

Parameters:
  • login_or_token – string
  • password – string
  • base_url – string
  • timeout – integer
  • client_id – string
  • client_secret – string
  • user_agent – string
  • per_page – int
FIX_REPO_GET_GIT_REF
Type:bool
per_page
Type:int
rate_limiting

First value is requests remaining, second value is request limit. :type: (int, int)

rate_limiting_resettime

Unix timestamp indicating when rate limiting will reset. :type: int

get_rate_limit()

Don’t forget you can access the rate limit returned in headers of last Github API v3 response, by github.MainClass.Github.rate_limiting and github.MainClass.Github.rate_limiting_resettime.

Calls:GET /rate_limit
Return type:github.RateLimit.RateLimit
oauth_scopes
Type:list of string
get_user(login=NotSet)
Calls:GET /users/:user or GET /user
Parameters:login – string
Return type:github.NamedUser.NamedUser
get_users(since=NotSet)
Calls:GET /users
Parameters:since – integer
Return type:github.PaginatedList.PaginatedList of github.NamedUser.NamedUser
get_organization(login)
Calls:GET /orgs/:org
Parameters:login – string
Return type:github.Organization.Organization
get_repo(full_name_or_id)
Calls:GET /repos/:owner/:repo or GET /repositories/:id
Return type:github.Repository.Repository
get_repos(since=NotSet)
Calls:GET /repositories
Parameters:since – integer
Return type:github.PaginatedList.PaginatedList of github.Repository.Repository
get_gist(id)
Calls:GET /gists/:id
Parameters:id – string
Return type:github.Gist.Gist
get_gists()
Calls:GET /gists/public
Return type:github.PaginatedList.PaginatedList of github.Gist.Gist
legacy_search_repos(keyword, language=NotSet)
Calls:

GET /legacy/repos/search/:keyword

Parameters:
  • keyword – string
  • language – string
Return type:

github.PaginatedList.PaginatedList of github.Repository.Repository

legacy_search_users(keyword)
Calls:GET /legacy/user/search/:keyword
Parameters:keyword – string
Return type:github.PaginatedList.PaginatedList of github.NamedUser.NamedUser
legacy_search_user_by_email(email)
Calls:GET /legacy/user/email/:email
Parameters:email – string
Return type:github.NamedUser.NamedUser
search_repositories(query, sort=NotSet, order=NotSet, **qualifiers)
Calls:

GET /search/repositories

Parameters:
  • query – string
  • sort – string (‘stars’, ‘forks’, ‘updated’)
  • order – string (‘asc’, ‘desc’)
  • qualifiers – keyword dict query qualifiers
Return type:

github.PaginatedList.PaginatedList of github.Repository.Repository

search_users(query, sort=NotSet, order=NotSet, **qualifiers)
Calls:

GET /search/users

Parameters:
  • query – string
  • sort – string (‘followers’, ‘repositories’, ‘joined’)
  • order – string (‘asc’, ‘desc’)
  • qualifiers – keyword dict query qualifiers
Return type:

github.PaginatedList.PaginatedList of github.NamedUser.NamedUser

search_issues(query, sort=NotSet, order=NotSet, **qualifiers)
Calls:

GET /search/issues

Parameters:
  • query – string
  • sort – string (‘comments’, ‘created’, ‘updated’)
  • order – string (‘asc’, ‘desc’)
  • qualifiers – keyword dict query qualifiers
Return type:

github.PaginatedList.PaginatedList of github.Issue.Issue

search_code(query, sort=NotSet, order=NotSet, **qualifiers)
Calls:

GET /search/code

Parameters:
  • query – string
  • sort – string (‘indexed’)
  • order – string (‘asc’, ‘desc’)
  • qualifiers – keyword dict query qualifiers
Return type:

github.PaginatedList.PaginatedList of github.ContentFile.ContentFile

render_markdown(text, context=NotSet)
Calls:

POST /markdown

Parameters:
Return type:

string

get_hook(name)
Calls:GET /hooks/:name
Parameters:name – string
Return type:github.HookDescription.HookDescription
get_hooks()
Calls:GET /hooks
Return type:list of github.HookDescription.HookDescription
get_gitignore_templates()
Calls:GET /gitignore/templates
Return type:list of string
get_gitignore_template(name)
Calls:GET /gitignore/templates/:name
Return type:github.GitignoreTemplate.GitignoreTemplate
get_emojis()
Calls:GET /emojis
Return type:dictionary of type => url for emoji`
create_from_raw_data(klass, raw_data, headers={})

Creates an object from raw_data previously obtained by github.GithubObject.GithubObject.raw_data, and optionaly headers previously obtained by github.GithubObject.GithubObject.raw_headers.

Parameters:
  • klass – the class of the object to create
  • raw_data – dict
  • headers – dict
Return type:

instance of class klass

dump(obj, file, protocol=0)

Dumps (pickles) a PyGithub object to a file-like object. Some effort is made to not pickle sensitive informations like the Github credentials used in the Github instance. But NO EFFORT is made to remove sensitive information from the object’s attributes.

Parameters:
  • obj – the object to pickle
  • file – the file-like object to pickle to
  • protocol – the pickling protocol
load(f)

Loads (unpickles) a PyGithub object from a file-like object.

Parameters:f – the file-like object to unpickle from
Returns:the unpickled object
get_api_status()

This doesn’t work with a Github Enterprise installation, because it always targets https://status.github.com.

Calls:GET /api/status.json
Return type:github.Status.Status
get_last_api_status_message()

This doesn’t work with a Github Enterprise installation, because it always targets https://status.github.com.

Calls:GET /api/last-message.json
Return type:github.StatusMessage.StatusMessage
get_api_status_messages()

This doesn’t work with a Github Enterprise installation, because it always targets https://status.github.com.

Calls:GET /api/messages.json
Return type:list of github.StatusMessage.StatusMessage