Package: pyShortUrl
A python library to shorten urls using various url shortening serices. Republished from the previously released library byParth Bhatt.Following table lists details for each of the supported services:DomainShorten/Expand URLsQR codebit.lyYESNObitly.comYESNOgimme.barYESNOgit.ioYESNOgoo.glYESYESis.gdYESNOj.mpYESNOtinyurl.comYESNOv.gdYESNOInstallTo install pyshorturl:python setup.py installUsing pyshorturlpyshorturl provides simple APIs that your python applications can use. Following
are some examples that show how you can use pyShortUrl with goo.gl.Using pyshorturl for URL shortening withgoo.glShorten a URL using goo.gl:from pyshorturl import Googl, GooglError

long_url = 'http://www.parthbhatt.com/blog/'
service = Googl(api_key=<your_api_key>)
try:
    short_url = service.shorten_url(long_url)
    print short_url
except GooglError, e:
    print 'Error: %s' %eExpand a goo.gl short url back to the original long url:from pyshorturl import Googl, GooglError

short_url = 'http://goo.gl/RwsEG'
service = Googl(api_key=<your_api_key>)
try:
    long_url = service.expand_url(short_url)
    print long_url
except GooglError, e:
    print 'Error: %s' %eGet QR code for a goo.gl short url:from pyshorturl import Googl, GooglError

short_url = 'http://goo.gl/RwsEG'
qr_img_path = '/path/to/qr_code.png'
service = Googl()
try:
    service.write_qr_image(short_url, qr_img_path)
except GooglError, e:
    print 'Error: %s' %eUsing pyshorturl for URL shortening withbit.ly,j.mpandbitly.comYou can use bit.ly exactly like you’d use goo.gl. Just initialize theserviceobject in the snippets above usingBitlyinstead ofGoogl.from pyshorturl import Bitly, BitlyError

service = Bitly(<your_bit.ly_login>, <your_bit.ly_api_key>)Note that it is mandatory to associate every call to bit.ly with a valid
account and an API Key. Hence, to use URL shortening with bit.ly you will need
to provide an account name and API key.To shorten a url usingj.mporbitly.com, specify the domain as an argument
to theshortenfunction call as shown below:from pyshorturl import Bitly, BitlyError

long_url = 'http://www.parthbhatt.com/blog/'
service = Bitly(<your_bit.ly_login>, <your_bit.ly_api_key>)
try:
    short_url = service.shorten_url(long_url, domain='j.mp')
    print short_url
except BitlyError, e:
    print '%s' %eUsing pyshorturl for URL shortening withtinyurl.comfrom pyshorturl import TinyUrlcom

service = TinyUrlcom()You dont need any account name or api key to use TinyUrl.Using the pyshorturl-cli.py utilitypyshorturl ships with a command-line utility calledpyshorturl-cli.pythat
allows you to use all the features of the library from the command line.$ python pyshorturl-cli.py -h
Options:
  -h, --help            show this help message and exit
  -r SERVICE, --service=SERVICE
                        One of the shortening services
                        goo.gl,bit.ly,tinyurl.com,v.gd,is.gd. Defaults to
                        goo.gl
  -d DOMAIN, --domain=DOMAIN
                        Domain bit.ly, j.mp or bitly.com to use while
                        shortening with bit.ly. Defaults to bit.ly
  -u LOGIN, --login=LOGIN
                        The user account to use with the url shortening
                        service.
  -l LONG_URL, --long-url=LONG_URL
                        Shorten the specified URL.
  -k SVC_API_KEY, --api-key=SVC_API_KEY
                        Use API Key while communicating with the url
                        shortening service.
  -s SHORT_URL, --short-url=SHORT_URL
                        Expand the specified Short URL.
  -q QR_IMG_PATH, --qr-code-file=QR_IMG_PATH
                        Used with -s. Writes the QR code for the corresponding
                        short url.Some examples of using the pyshorturl-cli.py utility:Shorten a long url using goo.gl:$ python pyshorturl-cli.py --service goo.gl --long-url http://www.parthbhatt.com/blog/2011/geolocation-with-google-maps-javascript-api/ --api-key <your-api-key>
http://goo.gl/NMdyGObtain the original long url for a goo.gl short url:$ python pyshorturl-cli.py --short-url http://goo.gl/NMdyG --api-key <your_goo.gl_api_key>
http://www.parthbhatt.com/blog/2011/geolocation-with-google-maps-javascript-api/Get the QR code for a goo.gl short url:$ python pyshorturl-cli.py --short-url http://goo.gl/NMdyG --qr-code-file qr_code.png
Wrote the qr code for http://goo.gl/NMdyG to qr_code.pngShorten a long url using bit.ly:$ python pyshorturl-cli.py --service bit.ly --login <your_bit.ly_account> --api-key <your_bit.ly_api_key> -l http://www.parthbhatt.com/blog/
http://bit.ly/xJHGkJShorten a long url using j.mp:$ python pyshorturl-cli.py --service bit.ly --login <your_bit.ly_account> --api-key <your_bit.ly_api_key> --domain j.mp -l http://www.parthbhatt.com/blog/
http://j.mp/xJHGkJObtain the original long url for a bit.ly short url:$ python pyshorturl-cli.py --service bit.ly --login <your_bit.ly_account> --api-key <your_bit.ly_api_key> -s http://bit.ly/xJHGkJ
http://www.parthbhatt.com/blog/Get the QR code for a bit.ly short url:$ python pyshorturl-cli.py --service bit.ly --login <your_bit.ly_account> --api-key <your_bit.ly_api_key> --short-url http://bit.ly/xJHGkJ --qr-code-file qr_code.png
Wrote the qr code for http://bit.ly/xJHGkJ to qr_code.pngShorten a long url using tinyurl.com:$ python pyshorturl-cli.py --service tinyurl.com --long-url http://www.parthbhatt.com/blog/
http://tinyurl.com/8yuvzl5Obtain the original long url for a tinyurl.com short url:$ python pyshorturl-cli.py --service tinyurl.com --short-url http://tinyurl.com/8yuvzl5
http://www.parthbhatt.com/blog/Shorten a long url using git.io:$ python pyshorturl-cli.py --service git.io --long-url https://github.com/parthrbhatt/pyShortUrl
https://git.io/sUX2IQRetrieve the original long url with git.io:$ python pyshorturl-cli.py --service git.io --short-url https://git.io/sUX2IQ
https://github.com/parthrbhatt/pyShortUrl