public
Description: Python interface for talking to the github API
Clone URL: git://github.com/dustin/py-github.git
ashcrow (author)
Sun Aug 31 21:19:08 -0700 2008
dustin (committer)
Sun Sep 07 21:01:07 -0700 2008
commit  1be68604d61e216cdcd069780e9f967630822924
tree    4e1c22acace7402db5f2320b19f533e058cd3867
parent  f46e25fbaa8923e169ddce7afbb2dc8339cc50d6
name age message
file .gitignore Thu Apr 10 09:19:56 -0700 2008 Working github user requestor. [dustin]
file README.markdown Sat May 24 12:56:13 -0700 2008 Lots of documentation. [dustin]
directory data/ Sat May 24 12:22:32 -0700 2008 Support for the search API. [dustin]
file ghsearch.py Sun Sep 07 21:01:07 -0700 2008 pep8 compliance [ashcrow]
file github.py Sun Sep 07 21:01:07 -0700 2008 pep8 compliance [ashcrow]
file githubsync.py Sun Sep 07 21:01:07 -0700 2008 pep8 compliance [ashcrow]
file githubtest.py Sun Sep 07 21:01:07 -0700 2008 pep8 compliance [ashcrow]
README.markdown

What’s on Github?

This is a library that implements github’s API in python.

Part of the reason I wrote this was to have a simple way to keep local clones of my projects. Included is githubsync.py which does that for any given user (within the limitations of the github API, which currently limits you to public projects).

Supported APIs

User

This code (which happens to be main in git.py)

import sys
u = GitHub().user(sys.argv[1])
print "User:  %s (%s)" % (u.login, u.name)
for repo in [u.repos[k] for k in sorted(u.repos.keys())]:
    print "- %s" % repo.name
    print "  %s" % repo.url
    print "  %s" % "git://github.com/%s/%s.git" % (u.login, repo.name)

Yields this result:

User:  dustin (Dustin Sallings)
- app-hider
  http://github.com/dustin/app-hider
  git://github.com/dustin/app-hider.git
- buildwatch
  http://github.com/dustin/buildwatch
  git://github.com/dustin/buildwatch.git
- cache_fu
  http://github.com/dustin/cache_fu
  git://github.com/dustin/cache_fu.git
- diggwatch
  http://github.com/dustin/diggwatch
  git://github.com/dustin/diggwatch.git
- environ
  http://github.com/dustin/environ
  git://github.com/dustin/environ.git

Search

Search for repos or descriptions matching the given search terms.

repos = GitHub().search('memcache')
for r in repos:
    print "%s has %d forks and %d watchers" % (
        r.name, r.forks, r.watchers)

Commits

Get the recent commits for a given repo.

commits = GitHub().commits('dustin', 'py-github')
for c in commits:
    print "%s: %s" % (c.id[:7], c.message.split('\n')[0])

Also, you may specify a particular branch:

commits = GitHub().commits('dustin', 'memcached', 'binary')
for c in commits:
    print "%s: %s" % (c.id[:7], c.message.split('\n')[0])

Commit

Fetch a specific commit and lots of details about it.

Note there is a lot of structured data in here this example doesn’t show. For example, modified files contain a full diff of each file, and every commit has a list of parent IDs (in the case of an octopus merge, there can be many). If you want more information, it’s quite likely there.

commit = GitHub().commit('gitmirror', 'git', 'c998ae9b')
print "%s made the change\n%s\nAffecting the following files:" % (
    commit.author.name, commit.message)
for c in commit.added: print "A", c.filename
for c in commit.removed: print "R", c.filename
for c in commit.modified: print "M", c.filename