API Reference

Client

class github.GHClient(*, username=None, token=None, user_cache_size=30, repo_cache_size=15, custom_headers={})

The main client, used to start most use-cases.

Parameters
  • username (Optional[str]) – An optional username to be provided along with a token to make authenticated API calls. If you provide a username, the token must be provided as well.

  • user_cache_size (Optional[int]) – Determines the maximum number of User objects that will be cached in memory. Defaults to 30, must be between 30 and 0 inclusive.

  • repo_cache_size (Optional[int]) – Determines the maximum number of Repository objects that will be cached in memory. Defaults to 15, must be between 30 and 0 inclusive.

  • custom_headers (Optional[dict]) – A way to pass custom headers into the client session that drives the client, eg. a user-agent.

username

The authenticated Client’s username, if applicable.

Type

Optional[str]

__token

The authenticated Client’s token, if applicable.

Type

Optional[str]

check_limits(as_dict=False)

Returns the remaining number of API calls per timeframe.

Parameters

as_dict (Optional[bool]) – Set to True to return the remaining calls in a dictionary. Set to False to return the remaining calls in a list. Defaults to False

await update_auth(*, username, token)

Allows you to input auth information after instantiating the client.

Parameters
  • username (str) – The username to update the authentication to. Must also be provided with the valid token.

  • token (str) – The token to update the authentication to. Must also be providede with the valid username.

await start()

Main entry point to the wrapper, this creates the ClientSession.

await get_self()

User: Returns the authenticated User object.

await get_user(*, user)

User: Fetch a Github user from their username.

Parameters

user (str) – The name of the user to fetch.

await get_repo(*, owner, repo)

Repository: Fetch a Github repository from it’s name.

Parameters
  • owner (str) – The name of the owner of a given reposiory.

  • repo (str) – The name of the repository to fetch.

await get_issue(*, owner, repo, issue)

Issue: Fetch a Github Issue from it’s name.

Parameters
  • owner (str) – The name of the owner of the repository for which the issue relates to.

  • repo (str) – The name of the repository to which the issue is related to.

  • issue (int) – The ID of the issue to fetch.

await create_repo(name, description='Repository created using Github-Api-Wrapper.', public=False, gitignore=None, license=None)

Creates a Repository with supplied data. Requires API authentication.

Parameters
  • name (str) – The name of the repository to be created.

  • description (str) – A description of the repository to be created.

  • public (bool) – Determines whether only the repository will be visible to the public. Defaults to False (private repository).

  • gitignore (Optional[str]) – .gitignore template to use. See https://github.com/github/gitignore for GitHub’s own templates. Defaults to None.

  • license (Optional[str]) – TODO: Document this.

Return type

Repository

await delete_repo(repo)

Delete a Github repository, requires authorisation.

Parameters

repo (str) – The name of the repository to delete.

Return type

Optional[str]

await get_gist(gist)

Fetch a Github gist from it’s id.

Parameters

gist (str) – The id of the gist to fetch.

Return type

Gist

await create_gist(*, files, description='Gist from Github-Api-Wrapper', public=True)

Creates a Gist with the given files, requires authorisation.

Parameters
  • files (List[File]) – A list of File objects to upload to the gist.

  • description (str) – A description of the gist.

  • public (bool) – Determines whether the gist will be visible to the public. Defaults to False (private).

Return type

Gist

await delete_gist(gist)

Delete a Github gist, requires authorisation.

Parameters

gist (int) – The ID of the gist to delete.

Return type

Optional[str]

await get_org(org)

Fetch a Github organization from it’s name.

Parameters

org (str) – The name of the organization to fetch.

Return type

Organization

await latency()

float: Returns the latency of the client.

await close()

Close the session.

API Models

APIObject

class github.APIObject

Top level class for objects created from the API

User

class github.User

Representation of a user object on Github.

login

The API name of the user.

Type

str

id

The ID of the user.

Type

int

avatar_url

The url of the user’s Github avatar.

Type

str

html_url

The url of the user’s Github page.

Type

str

created_at

The time of creation of the user.

Type

datetime.datetime

PartialUser

class github.PartialUser

Repository

class github.Repository

Representation of a repository on Github.

id

The ID of the repository in the API.

Type

int

name

The name of the repository in the API.

Type

str

owner

The owner of the repository.

Type

User

created_at

The time the repository was created at.

Type

datetime.datetime

updated_at

The time the repository was last updated.

Type

datetime.datetime

url

The API url for the repository.

Type

str

html_url

The human-url of the repository.

Type

str

archived

Whether the repository is archived or live.

Type

bool

open_issues_count

The number of the open issues on the repository.

Type

int

default_branch

The name of the default branch of the repository.

Type

str

property is_fork

Whether the repository is a fork.

Type

bool

property language

Primary language of the repository.

Type

str

property open_issues

The number of open issues on the repository.

Type

int

property forks

The number of forks of the repository.

Type

int

property default_branch

The default branch of the repository.

Type

str

await delete()

Deletes the repository.

await add_file(filename, message, content, branch=None)

Adds a file to the repository.

Parameters
  • filename (str The name of the file.) –

  • message (str The commit message.) –

  • content (str The content of the file.) –

  • branch (str The branch to add the file to, defaults to the default branch.) –

Issue

class github.Issue

Representation of an issue on Github.

id

The ID of the issue in the API.

Type

int

title

The title of the issue in the API.

Type

str

user

The user who opened the issue.

Type

User

labels

TODO: document this.

Type

List[str]

state

The current state of the issue.

Type

str

created_at

The time the issue was created.

Type

datetime.datetime

closed_by

The user the issue was closed by, if applicable.

Type

Optional[Union[PartialUser, User]]

property updated_at

The time the issue was last updated, if applicable.

Type

Optional[datetime.datetime]

property html_url

The human-friendly url of the issue.

Type

str

File

class github.File

A wrapper around files and in-memory file-like objects.

Parameters
  • fp (Union[str, io.StringIO, io.BytesIO]) – The filepath or StringIO representing a file to upload. If providing a StringIO instance, a filename shuold also be provided to the file.

  • filename (str) – An override to the file’s name, encouraged to provide this if using a StringIO instance.

Gist

class github.Gist

Representation of a gist on Github.

id

The ID of the gist in the API.

Type

int

html_url

The human-friendly url of the gist.

Type

str

files

A list of the files in the gist, can be an empty list.

Type

List[File]

public

Whether the gist is public.

Type

bool

owner

The owner of the gist.

Type

Union[PartialUser, User]

created_at

The time the gist was created at.

Type

datetime.datetime

property updated_at

The time the gist was last updated, if applicable.

Type

Optional[datetime.datetime]

property comments

document this.

Type

TODO

property discussion

document this.

Type

TODO

property raw

document this.

Type

TODO

await delete()

Delete the gist.

Organization

class github.Organization

Representation of an organization in the API.

login

TODO: document this

Type

str

id

The ID of the organization in the API.

Type

int

is_verified

Whether or not the organization is verified.

Type

bool

created_at

The time the organization was created at.

Type

datetime.datetime

avatar_url

The url of the organization’s avatar.

Type

str

property description

The description of the organization.

Type

str

property html_url

The human-friendly url of the organization.

Type

str