Python | How to shorten long URLs using Bitly API Last Updated : 22 Oct, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report Bitly is used to shorten, brand, share, or retrieve data from links programmatically. In this article, we'll see how to shorten URLs using Bitly API. Below is a working example to shorten a URL using Bitly API. Step #1: Install Bitly API using git git clone https://github.com/bitly/bitly-api-python.git Go inside the folder using: cd bitly-api-python Note: In case installation with pip command is not working: Python3 1== File "/usr/local/lib/python3.5/dist-packages/bitly_api/__init__.py", line 1, in from bitly_api import Connection, BitlyError, Error ImportError: cannot import name 'Connection' Uninstall bitly-api in case already installed using pip: pip uninstall bitly_api Step #2: Install in Python's folder for modules: python setup.py install Note: Delete the source code using (since we don't need it for now) : cd../ rmdir bitly-api-python-master Step #3: To get "Bitly username and API Key" login to account on bit.ly and then go here and get it. In case of further assistance, one can go here. Step #4: Now create a file shorturl.py and write this code: Python3 1== import bitly_api API_USER = "your_username" API_KEY = "your_API_Key" b = bitly_api.Connection(API_USER, API_KEY) # Replace this with your Long URL Here longurl = www.google.com response = b.shorten(uri = longurl) # Now let us print the Bitly URL print(response) Step #5: Run the file 'shorturl.py'. Reference: https://dev.bitly.com/v4_documentation.html Comment More infoAdvertise with us Next Article Building CLI to check status of URL using Python R RishabhAgrawal6 Follow Improve Article Tags : Python Technical Scripter 2018 Practice Tags : python Similar Reads How to get current_url using Selenium in Python? While doing work with selenium many URL get opened and redirected in order to keeping track of URL current_url method is used. The current_url method is used to retrieve the URL of the webpage the user is currently accessing. It gives the URL of the current webpage loaded by the driver in selenium. 2 min read Building CLI to check status of URL using Python In this article, we will build a CLI(command-line interface) program to verify the status of a URL using Python. The python CLI takes one or more URLs as arguments and checks whether the URL is accessible (or)not. Stepwise ImplementationStep 1: Setting up files and Installing requirements First, cr 4 min read How to build a URL Shortener with Django ? Building a URL Shortener, Is one of the Best Beginner Project to sharpen your Skills. In this article, we have shared the steps to build a URL shortener using Django Framework. SetupWe need some things setup before we start with our project. We will be using Virtual Environment for our project.pip i 5 min read Convert binary to string using Python We are given a binary string and need to convert it into a readable text string. The goal is to interpret the binary data, where each group of 8 bits represents a character and decode it into its corresponding text. For example, the binary string '01100111011001010110010101101011' converts to 'geek' 3 min read How to Urlencode a Querystring in Python? URL encoding a query string consists of converting characters into a format that can be safely transmitted over the internet. This process replaces special characters with a '%' followed by their hexadecimal equivalent. In this article, we will explore three different approaches to urlencode a query 2 min read Parsing and Processing URL using Python - Regex Prerequisite: Regular Expression in Python URL or Uniform Resource Locator consists of many information parts, such as the domain name, path, port number etc. Any URL can be processed and parsed using Regular Expression. So for using Regular Expression we have to use re library in Python. Example: U 3 min read Like