URL shortener using python

In this article, we shall see how to create a TinyURL link for our long URLs. This can be performed using a python library called pyshorteners which is a python wrapper built around the TinyURL website. With the help of this library, we can get a shortened URL for our app with just three lines of code.

What is tinyurl?

TinyURL is a URL shortening web service, which provides short aliases for redirection of long URLs. 

For example this

https://www.youtube.com/watch?v=9jbwtx1-tw0&list=RD9jbwtx1-tw0&start_radio=1

can be converted to


http://tinyurl.com/y7sxkbew

this with the help pf tinyURL.

Installation

The library can be easily installed using pip as

pip install pyshorteners

Example

This is a sample example to generate a short url.

url shortener

The output of the above code snippet is,

http://tinyurl.com/y7sxkbew

Conclusion

That is it. We have generated our shortened URL with the help of this library in 3 lines of code. Hope this article was helpful.

Happy coding!