In [1]:
import github
We initialize the API object by adding an access token:
In [2]:
api = github.API(token="...")
If we want to list all repositories which the authenticated user has access to, we do it with the following command, which returns a list of Repository objects.
In [3]:
api.repositories.list()
Out[3]:
If we want the names of these repositories:
In [4]:
[repository.full_name for repository in api.repositories.list()]
Out[4]:
More detailed information about specific repositories we get with the get function.
In [5]:
repository = api.repositories.get("QuicksilverMachine/github_api")
repository.description
Out[5]:
Save command is used to save the changes on a repository.
In [6]:
repository.description = "A small python library to interface with Github API. - changed with api"
repository.save()
GitHub api has a limit on a number of requests that can be made to it. The rate_limits property returns a dictionary with detailed information about request limits.
In [7]:
api.rate_limits
Out[7]:
Only the standard request remaining count:
In [8]:
api.standard_requests_remaining
Out[8]:
The next_rate_limit_reset property returns a datetime object with the time of the next rate_limit count reset.
In [9]:
api.next_rate_limit_reset
Out[9]:
Every repository has a list of collaborators, whose usernames are retrieved with:
In [10]:
[user.login for user in repository.collaborators.list()]
Out[10]:
Repository owner is retrieved with:
In [11]:
user = repository.owner
The add function causes an invitation to be sent to a user for them to be added to a repository collaborator list, however in this case we can't add the owner of the repository as a collaborator, so the libraty raises an exception with the error message from the GitHub response.
In [12]:
repository.collaborators.add(user)
In [ ]: