URL Shorteners and its API in Python | Set-2
Prerequisite: URL Shorteners and its API | Set-1
Let’s discuss few more URL shorteners using the same pyshorteners module.
- Bitly URL Shortener: We have seen Bitly API implementation. Now let’s see how this module can be used to shorten a URL using Bitly Services.
Code to Shorten URL:
frompyshortenersimportShortenerACCESS_TOKEN='82e8156..e4e12c6'url_shortener=Shortener('Bitly', bitly_token=ACCESS_TOKEN)print("Short URL is {}".format(url_shortener.short(url)))chevron_rightfilter_noneOutput:

Code to Expand URL:
frompyshortenersimportShortenerACCESS_TOKEN='82e8156...c1dce4e12c6'url_expander=Shortener('Bitly', bitly_token=ACCESS_TOKEN)print("Long URL is {}".format(url_expander.expand(url)))chevron_rightfilter_noneOutput:
- Adf.ly URL Shortener:This is the URL Shortening Service that pays on the basis of number of visitors that visit your shortened URL. You need to Signup and create an API Key in order to use this service.
- You will get a link to Signup on the top rightmost corner of the Adf.ly webpage. There is an option to create either type of account: Create account to shorten URL and earn money or to Create account and Pay to advertise your website on Adf.ly Webpage.
- Once You will signup and confirm your email address, you will be redirected to the login page.
- After successful login, dashboard of your account will open up and you see an option Tools.
- Under Tools page, you will get your client id and API Key.
Note: There will be a message, Your API Access is currently disabled. Click Here to enable it.


Code to Shorten the URL:
frompyshortenersimportShortener# uid means User Id and key means API Key.url_shortener=Shortener('Adfly', uid='20727891', key='b8de8e0...5a2381241c',type='int')print("Short URL is {}".format(url_shortener.short(url)))chevron_rightfilter_noneOutput:
- Osdb URL Shortener: This is another simple URL shortening service. You don’t need an API Key to use this. Just type the url and see the magic. This site does not provide features like tracking the visitors on the shortened URL.
Code to Shorten the URL:
frompyshortenersimportShortenerurl_shortener=Shortener('Osdb')print("SHORT URL is {}".format(url_shortener.short(url)))chevron_rightfilter_noneOutput:
- da.gd URL Shortener: This URL shortening service provides you the option to customise the shorten URL just like Bitly.
Code to Shorten URL:
frompyshortenersimportShortenerurl_shortener=Shortener('Dagd')print("Short URL is {}".format(url_shortener.short(url)))chevron_rightfilter_noneOutput:
References:
- https://pypi.org/project/pyshorteners/
- https://adf.ly/
Recommended Posts:
- URL Shorteners and its API in Python | Set-1
- Pros and Cons of URL Shorteners
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
- Python | Add Logging to Python Libraries
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to a Python Script
- Python | Sort Python Dictionaries by Key or Value
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- chr() in Python
- abs() in Python
- Python Set | pop()
- SHA in Python
- SQL using Python | Set 1
- zip() in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



