Skip to content

Instantly share code, notes, and snippets.

@myano
Last active December 16, 2015 23:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save myano/5515295 to your computer and use it in GitHub Desktop.
Save myano/5515295 to your computer and use it in GitHub Desktop.

Create git.io Short URLs in Python

git.io is an awesome URL shortener provided by Github. It works when shortening URLs from *.github.com/* to a small https://git.io/ link.

requests

>>> import requests
>>> requests.post('https://git.io/create', {'url': 'https://github.com/myano/lmddgtfy'}).text
u'tZmc2g'

requests can be installed via pip

urllib / urllib2

>> import urllib
>> import urllib2
>> urllib2.urlopen(urllib2.Request('https://git.io/create', urllib.urlencode({'url': 'https://github.com/myano/lmddgtfy'}))).read()
'tZmc2g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment