- Authors
Ask Solem (askh@opera.com)
- Version
0.2.0
This is an experimental python library implementing all of the features available in version 2 of the Github API.
Note This software is not finished. And is likely to change in the near future.
You should read the developer documentation for the Github API first.
You can install python-github2
either via the Python Package Index (PyPI) or from source.
To install using pip
,:
$ pip install github2
To install using easy_install
,:
$ easy_install github2
If you have downloaded a source tarball you can install it by doing the following,:
$ python setup.py build
# python setup.py install # as root
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="........")
Or for an unauthenticated connection:
>>> github = Github()
API calls are limited by github.com 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)
>>> results = github.users.search("foo")
>>> user = github.users.show("ask") >>> user.name "Ask Solem"
>>> github.users.followers("ask") ['greut', 'howiworkdaily', 'emanchado', 'webiest']
>>> github.users.following("ask") ['sverrejoh', 'greut', 'jezdez', 'bradleywright', 'ericflo', 'howiworkdaily', 'emanchado', 'traviscline', 'russell']
>>> github.users.follow("jezdez")
>>> github.users.unfollow("jezdez")
>>> github.issues.list("ask/chishop", state="open") >>> github.issues.list("ask/chishop", state="closed")
>>> issues = github.issues.search("ask/chishop", "version twice") >>> issues[0].title 'Upload hangs on attempted second file.'
>>> github.issues.search("ask/chishop", term="authorization", ... state="closed")
>>> issue = github.issues.show("ask/chishop", 1) >>> issue.title 'Should not be able to upload same version twice.'
>>> comments = github.issues.comments("ask/chishop", 5) >>> comments[0].body 'Fix merged into /ask branch.'
>>> new_issue = github.issues.open("ask/chishop", title="New bug", ... body="This is a test bug") >>> new_issue.number 2
>>> github.issues.close("ask/chishop", new_issue.number) >>> github.issues.reopen("ask/chishop", new_issue.number)
>>> github.issues.add_label("ask/chishop", 2, "important")
>>> github.issues.remove_label("ask/chishop", 2, "important")
>>> github.issues.edit("ask/chishop", 3, title="New title", ... body="New body")
>>> github.get_network_meta("ask/chishop")
>>> github.get_network_data("schacon/simplegit", ... nethash="fa8fe264b926cdebaab36420b6501bd74402a6ff")
>>> repositories = github.repos.search("django")
>>> repo = github.repos.show("schacon/grit") >>> repo.homepage "http://grit.rubyforge.org/"
# By default lists all repos for the current user. >>> repos = github.repos.list()
>>> repos = github.repos.list("schacon")
>>> github.repos.watch("schacon/grit")
>>> github.repos.unwatch("schacon/grit")
>>> fork = github.repos.fork("schacon/grit")
>>> new_repo = github.repos.create(name, description, homepage, ... public=True)
>>> github.repos.delete(name)
>>> github.repos.set_private("ask/chishop")
>>> github.repos.set_public("ask/chishop")
>>> pushables = github.repos.pushable()
>>> collabs = github.repos.list_collaborators("ask/chishop")
>>> github.repos.add_collaborator("ask/chishop", "schacon")
>>> github.repos.remove_collaborator("ask/chishop", "schacon")
>>> watchers = github.repos.watchers("ask/chishop")
>>> github.repos.network("ask/chishop")
Get a list of tags
>>> tags = github.repos.tags("ask/chishop")
Get a list of remote branches
>>> branches = github.repos.branches("ask/chishop")
>>> commits = github.commits.list("mojombo/grit", "master")
>>> commits = github.commits.list("mojombo/grit", "master", ... file="grit.gemspec")
>>> commit = github.commits.show("mojombo/grit", ... sha="5071bf9fbfb81778c456d62e111440fdc776f76c")
>>> tree = github.get_tree(project, tree_sha)
>>> blob = github.get_blob_info(project, tree_sha, path)
This software is licensed under the New BSD License
. See the LICENSE
file in the top distribution directory for the full license text.