Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most suitable python library for Github API v3 [closed]

Tags:

python

github

api

I am looking for a python library for the Github APIv3 suitable for me.

I found one library (python-github3) mentioned in the GH API docs. After playing around with it in ipython for an hour or two, I found it really unintuitive to explore/work with. I looked some more, and found there's quite a number of people at least attempting to write such a library. The more promising-looking (at a glance) are PyGithub and another python-github3, which apparently is different from the first one.

Before I spend the next days consecutively trying out library after library, I wanted to ask the SO community if there is an accepted, definitive, obvious choice for that library?

What I didn't like about the first library was the (to me) unintuitive way to get at data - some things you get as attributes, some you get as return value of a method, that return value is some complicated object which has to be paged and iterated through, etc.

In that regard, PyGithub looks more attractive at first glance - clearly drill down through an object hierarchy, and then arrive at the attribute containing what you want:

for repo in g.get_user().get_repos(): print repo.name

So, any pearls of wisdom to share? I know I don't have skills enough to quickly judge library quality, which is why I'm turning to the SO community.

edit: fwiw, I ended up using PyGithub. It works well, and the author is really receptive for feedback and bug reports. :-)

like image 910
Christoph Avatar asked May 16 '12 19:05

Christoph


People also ask

Is GitHub a Python library?

PyGitHub is a Python library to access the GitHub REST API. This library enables you to manage GitHub resources such as repositories, user profiles, and organizations in your Python applications.

What is PyGitHub?

PyGithub is a Python library to use the Github API v3. With it, you can manage your Github resources (repositories, user profiles, organizations, etc.) from Python scripts.

How do I fetch API in GitHub?

To get the list of random users, you have to make a request to the /user endpoint, and to get the details of a specific user, you make a request to the /user/{username} endpoint. You can try out the following commands quickly in your terminal with curl to see the results.


1 Answers

Since you mentioned you are a beginner python programmer, I would suggest you to try to use the JSON API without any Github library first. It really isn't that difficult and it will help you a lot later in your programming life since same approach can be applied to any JSON API. Especially if it seems that trying out libraries will take days.

I'm not saying that some library isn't easier to use, I'm just saying the small extra effort to use the API directly might be worth it in the long run. At least it will help you understand why some of those libraries seem "unintuitive" (as you said).

Simple example to fetch creation time of django repository:

import requests import json r = requests.get('https://api.github.com/repos/django/django') if(r.ok):     repoItem = json.loads(r.text or r.content)     print "Django repository created: " + repoItem['created_at'] 

This is using the popular requests library. In your code you'll naturally need to handle the error cases too.

If you need access with authentication it will be a bit more complex.

like image 185
Lycha Avatar answered Sep 21 '22 00:09

Lycha