URL Shortener

Published on . Written by

URL Shortener
Nowadays people pay a lot of attention to how things look, that is why sometimes, websites make use of a URL Shortener, to make their website’s URL more presentable. Now, there are many ways one can achieve this shortening. There are several in-built functions available, and there are even hosted websites that offer you a platform to shorten your URL.

Read more..
We have all come across certain articles which have a large URL pasted in it, and it ruins the aesthetics of the entire webpage. This is where URL shorteners can be used to make the web-page more presentable. This time around we will be taking a look at how to build a simple URL shortener using Python.


Skyfi Labs Projects
Project Description

URL Shorteners help website owners reduce the length of their unique web-page address, making it easier to share the website on various platforms. This because extremely crucial in cases where there is a limitation on the number of characters that can be sent, like in a text message or social media post. Long URLs that haven’t been shortened when cut leads to error in loading the webpage and the entire reason for pasting the URL gets nullified. In such cases, people can make use of such shorteners to trim their URLs and make them within the specified restrictions.

Concepts Used

  • Logical Analysis
  • Algorithm Representation
  • Bitwise manipulation
  • Abstraction concepts
  • Python Fundamentals
  • Database Management
  • Flash Fundamentals
Components Required

  1. A suitable OS such as Windows/Linux/Mac
  2. Python 2 or upwards installed
  3. Python module that supports shortening must be installed, such as pyshorteners
  4. Base62 Encoder/Decoder
  5. Flask
  6. SQLite3
Advantages of URL shortening

  • Easier to remember URL
  • Easier to share URL
  • Easier to maintain the URL
  • Easier to post on social media
  • Can be used even when there are restrictions on the number of characters
Project Implementation

  1. URL shortening requires two things:
  • A String mapping algorithm that will allow you to map long strings to make them into short strings using Base 62
  • A simple web framework such as Flask or Tornado that pints the URL you created towards the actual URL.
  1. Create a database that stores the actual URL of the website.
  2. Now, allocate a Primary Key to all these URLs.
  3. Create an algorithm that generates a string when a PK is passed to it.
  4. Next, use a mapper to map that string created to the original URL stored in the database.
  5. In this process, we are not actually reducing the string size, but rather abstracting the actual string to make it look shorter.
  6. Once you have mapped the URL onto a smaller string, pass that URL onto the user.
  7. You can also define an option to allow the user to input the URL, so as to gain input and add that URL to the database created.
  8. Anytime someone sends out a request for that URL through your shortened version, it will look up the mapped original URL, and redirect the webpage there so that you open to the right site.
  9. Use a Base62 algorithm to convert a large number of strings into a smaller-sized one. A Base62 Encoder makes the URL smaller, while a Decoder may be used to map the short one to the long one, enabling users to access the right website when needed.
  10. If you are using older versions of Python, you might need to install or import the following libraries:
  • import contextlib
  • parse import urlencode
  • urllib import urlencode
  • request import urlopen
  • urllib2 import urlopen
  • import sys
  1. Python libraries use bit-shuffling to prevent generating predictable URLs.
  2. The number of digits and alphabets are completely random in such libraries, and they use mall-case characters by default.
  3. They usually employ a prime number of digits and characters to increase the efficiency of the algorithm.
Kit required to develop URL Shortener:
Technologies you will learn by working on URL Shortener:


Any Questions?


Subscribe for more project ideas