Launch Website URL shortcut using Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 30 Likes Like Report In this article, we are going to launch favorite websites using shortcuts, for this, we will use Python's sqlite3 and webbrowser modules to launch your favorite websites using shortcuts. Both sqlite3 and webbrowser are a part of the python standard library, so we don't need to install anything separately. The best part about this is that because we are using a database to store the websites and their shortcuts, your favorite websites will remain saved in the database even if we close the terminal or shut down the PC. So you don't need to add your favorite websites to the database every time you execute the script. Approach:We create a new database if it does not already exist and connect it to our database.We create different functions to fetch data from the database, open a website, add a new website to the database, and remove a website from the databaseWe call a while loop so that our program can listen to the user's commands until they quitWe ask for a response from the user to perform a specific taskBelow is the implementation: Python3 import webbrowser import sqlite3 # connecting to sqlite and creating # an actual database conn = sqlite3.connect("favorites.db") c = conn.cursor() c.execute("""CREATE TABLE IF NOT EXISTS favorites (title TEXT, url TEXT)""") # Created a table named favorites # (if it didn't already existed). # Then inserted the headers title # (which takes text as input) # and url (which takes text as input) def get_data(): """ Used to extract data from our database """ c.execute('''SELECT * FROM favorites''') results = c.fetchall() return results def get_fav(titl): """ Used to extract the favorite website """ c.execute('''SELECT * FROM favorites WHERE title=?''', (titl, )) return c.fetchone() def add_fav(titl, url): """ Used to add a new favorite website """ c.execute("""INSERT INTO favorites (title, url) VALUES (?, ?)""", (titl, url)) conn.commit() def remove_fav(titl): """ Used to remove a favorite website from the database """ c.execute('''DELETE FROM favorites WHERE title=?''', (titl, )) conn.commit() # A loop to listen to commands from the user while True: print() # printing each statement like # this to keep the code clean print("Press v to visit a favorite,", end=" ") print("ls for list,", end=" ") print("add to add a new item,", end=" ") print("rm to delete,", end=" ") print("q to quit:", end=" ") # taking input command from the user response = input("") if response.lower() == "v": shortcut = input("Enter the shortcut for the website: ") record = get_fav(shortcut) try: # opening the selected website in the browser webbrowser.open(record[1]) except TypeError: # if we don't have the shortcut # in the database, print this: print('This shortcut does not exist in the database') elif response.lower() == "ls": # printing the items in the database print(get_data()) elif response.lower() == "add": # adding a new website to the database destination = input( "Enter URL for the shortcut (Example -> https://gen.xyz/): ") # adding the shortcut to the above website in # the database shortcut = input("Enter the shortcut for the URL: ") add_fav(shortcut, destination) elif response.lower() == "rm": # removing an item from the database shortcut = input( "Enter the shortcut for the URL you want to remove: ") remove_fav(shortcut) print("Removed Successfully") elif response.lower() == "q": break else: print("Enter a valid command") Output: Code Execution Create Quiz Comment U urvishmahajan Follow 30 Improve U urvishmahajan Follow 30 Improve Article Tags : Python Blogathon Blogathon-2021 python-utility Python-SQLite +1 More Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like