Today we will see how to make a url shortner in python it is very simple any one can create it you don’t have to use third party url shorteners now which shows ads and are not free because we will make our own url shortener in python for free.
We will use a python library for this project which is used to shorten links which is free and can be easily installed with pip which is a package manger for python.
Before seeing how to make a url shortener in python if you are intrested in more python projects or other projects than you can visit coderzway projects where I upload more coding projects like this visit coderzway projects.
How to make url shortener in python
Contents
So before starting if you don’t have python installed on your machine than you can download it from python website and install it remember to check add python to path – download python.
I will be using vs code to write python code you can use any editor of your choice I will recommend vs code because it is small and fast you can download vs code from here – download vs code.
1. Create a python file
First you need to create a python file with .py extension you can create a file in a seperate folder or anywhere we will just require one python file.
2. Install pyshortener
Now you need to install the python library which will do the most of the work no need to write complex code this library will do everything in the background so you need to install pyshortener
Pyshortener is a url shortening python library which is used to build short links easily and there are lot of api you can use you can browse pyshortener docs here.
To install pyshortener open command prompt or terminal at the file location and type or paste this command.
3. Copy and paste
Now you have created the file now you need to write the code so you can copy the below code and paste it into the file
You must be shocked that it is just 5 lines of code that’s a great advantage of python because it has lot of libraries.
You can run the file by typing or pasting the below command
4. Output
Enter the full url you want to shortern it will give you a url which you can paste in the browser and you will be redirected to your main website.
Summary
So this was how to make a url shortener in python it was a simple project with just 5 lines of python code you can explore more and expand open it.
I hope you found what you were looking for and you found this guide useful if you want more guides and projects like this than do subscribe to our newsletter thank you have a nice day.
0 Comment