GitHub API usage example

import pandas as pd
%load_ext restmagic

Some calls require personal API token: https://blog.github.com/2013-05-16-personal-api-tokens/

token = ''
%%rest_root https://api.github.com
Accept: application/vnd.github.v3+json
Authorization: Token $token
Requests defaults are set.

Get top 10 forked projects from the GitHub, for the “ipython” query

r = %rest -q search/repositories?q=ipython&sort=forks&per_page=10
df = pd.DataFrame(r.json()['items'], columns=('full_name', 'forks_count', 'watchers'))
df.set_index('full_name', inplace=True)
df
forks_count watchers
full_name
wesm/pydata-book 6052 6585
donnemartin/data-science-ipython-notebooks 4047 13738
ipython/ipython 3643 13004
jrjohansson/scientific-python-lectures 1319 2256
jdwittenauer/ipython-notebooks 1086 1935
jupyterhub/jupyterhub 827 3631
PipelineAI/pipeline 775 2950
powerline/powerline 741 9322
ogrisel/parallel_ml_tutorial 571 1444
jadianes/spark-py-notebooks 570 832
df.plot(kind='barh')
<matplotlib.axes._subplots.AxesSubplot at 0x7fa2b0a0a8d0>
../_images/github_7_1.png

Follow Github User

Personal API token is required to perform the call: https://blog.github.com/2013-05-16-personal-api-tokens/

%rest PUT user/following/gvanrossum
<Response [204]>

Unfollow GitHub user

%rest -q DELETE user/following/gvanrossum
<Response [204]>

Search GitHub for “pritn” string in Python code

r = %rest -q search/code?q=pritn+in:file+language:python
data = r.json()
urls = [i['html_url'] for i in data['items']]
print('\n'.join(urls))
print("== {0} of total {1} ==".format(len(urls), data['total_count']))
https://github.com/Ramieltje/octotelegram/blob/a5a15408ce586c6defdcbd54a6fae7195deb38dd/CS1301%20exercises/Hello%20world.py
https://github.com/abdallah-ali-abdallah/Simply-Raspberry-Pi-Book/blob/6f273337b76ba8083abf74cd9652ad187896392c/Attachments/1-%20Python%20Examples%20(Source%20Codes)/4-1%20Motion%20Detector.py
https://github.com/runei/IA/blob/77fa1e103162e67b7823ca1ea4dbed396afb3a88/trabDCG.py
https://github.com/infixsrf/Trash/blob/4d0493cdad38e48f3f63a9ef95877fa52df7bd4c/programmer.py
https://github.com/lxxcumt/learnpython/blob/b63b01b31c283962576cd0dc2d55ee97e9f48d13/ex25.py
https://github.com/CHTramp/Git-/blob/90e8339a52a571c88d2b6e68e9475593c846517f/Python%E8%AF%BE%E7%A8%8B%E4%BB%A3%E7%A0%81/%E8%AF%BE%E7%A8%8B%E5%AD%A6%E4%B9%A0%E4%BB%A3%E7%A0%81/day6-%E5%87%BD%E6%95%B0%E6%93%8D%E4%BD%9C/%E5%87%BD%E6%95%B0%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86%E7%9A%84homework.py
https://github.com/deepnighttwo/deepnighttwo/blob/baeee505d1d48a92adaff874552c0db08f32e6bb/myutilities/workpy/parseasindetailshead/parseasindetailsheadline.py
https://github.com/MHM18/hm18/blob/cee7c3220c76c4046ee6ba23c3c8459fa21fc485/hmpro/zhangxiyang/import_file2.py
https://github.com/Alex1996a/ML/blob/a5c79631d0d7058669949814c4300ee53224e6f6/RL/treaser_on_right.py
https://github.com/MHM18/hm18/blob/cee7c3220c76c4046ee6ba23c3c8459fa21fc485/hmpro/zhangxiyang/test4.py
https://github.com/MHM18/hm18/blob/cee7c3220c76c4046ee6ba23c3c8459fa21fc485/hmpro/zhangxiyang/test5.py
https://github.com/MHM18/hm18/blob/cee7c3220c76c4046ee6ba23c3c8459fa21fc485/hmpro/zhangxiyang/dictionary/import_file/import_file5.py
https://github.com/shenxiangzhuang/PythonDataAnalysis/blob/3c096c86836c479e2ac305d09c8fa9aa04303825/Ch2Data/DataIO/Mpymysql/Mbase.py
https://github.com/ktomczuk/pythonbootcamp/blob/87d9be61b773d9b9b53e4087294765555a67f216/z3/2.py
https://github.com/MHM18/hm18/blob/cee7c3220c76c4046ee6ba23c3c8459fa21fc485/hmpro/zhangxiyang/dictionary/import_file/import_file3.py
https://github.com/jjnguy/PublicFun/blob/c4538a3aba8e0ed4e91286b408c47b2d079c69a1/coms362_Project/src/ID3Tag.py
https://github.com/chenxizhan/docs/blob/310d8bbdd8163605e486bfcc69a9de28b60604ff/doc-root/python/samples/ch8.py
https://github.com/ali225/Python-Examples-Source-Codes-With-Raspberry-PI-project/blob/bd1c5d060e360223770f072c40515e990390e532/4-1%20Motion%20Detector.py
https://github.com/tyouei/python_deepi/blob/d0af7fe4ced51c433790dd4600a04beb1be72a92/base/python_cpitalize.py
https://github.com/yucefsourani/taalam-kotob/blob/fb235e300f309d3ef574889ce767a1786aa39f10/raspberry_pi/Attachments/1-%20Python%20Examples%20(Source%20Codes)/4-1%20Motion%20Detector.py
https://github.com/ncarkaci/Ag-ve-Bilgi-Guvenligi-Ders-Notlari/blob/bd074c1b93b3ea07058f371f607ad827245fb838/3.%20Ders%20Python/lecture6.py
https://github.com/Subashini06/SUBA/blob/9ef1062d6529fb1ab8b2e7a017bcda2d5d64c661/printingnxtnum.py
https://github.com/TakiyaHideto/python/blob/adae181a4bd9535c0c9a0277239f83ec065c2bc7/ele.me/CountScoreFresh.py
https://github.com/svatozde/DDW-HW4/blob/8ec82b068a5ad69269a08da1b4ece5889615c2a2/HW4.py
https://github.com/nolsen97/cs1113/blob/b1f1d397509871a74a26283239cb5fd9c0468c1e/hello.py
https://github.com/ruuuu/massenger_gb/blob/efa4635d5c4995f0da3a461c77cc4ee3a413b2a9/First.py
https://github.com/BowenH98/test/blob/fbf1f3f4c7d723aaa173a1ec550d595e48064d77/Assigment_1_final_version.py
https://github.com/trossossp3/Python/blob/67fd60dd2d2cbde6b06d8befc6ea5896a17470b0/DMOJ/hello.py
https://github.com/GIHUNKIM/impython/blob/9c72e7bcc458abb9ae315bb49268741882f17b05/PythonApplication17/PythonApplication17/PythonApplication17.py
https://github.com/cbaikuntha/Safi1/blob/b8e92a2246256e497d394f3dedb364b528ebbd0c/f_Safi.py
== 30 of total 672 ==