How to download and install urllib3 in Python?

Ads
 

How to download and install urllib3 in Python?

In this tutorial we are going to download and install urllib3 in Python or in Anaconda Python. After installing we will also learn to make example program using urllib3 package of Python.

In this tutorial we are going to download and install urllib3 in Python or in Anaconda Python. After installing we will also learn to make example program using urllib3 package of Python.

Installing urllib3 in Python - How to download install urllib3 in Python? Write urllib3 python 3 example

In this tutorial we are going to download the urllib3 package of python and then install it on the Python 3 environment. We will also show you how you can install the urllib3 package on the Anaconda distribution of Python. The urllib3 is one of the most used library in Python which is used for working with the server through http protocol. You also learn to make simple program using the urllib3 library in Python  3.

This library is one of the most used library in Python for accessing the URL and performing various types of interaction with the HTTP server from Python program. In this tutorial we will learn urllib3 library in detail. We will also show you many examples of urllib3.

What is urllib3?

The urllib3 is Python library for working the the HTTP server and handling various types of HTTP requests in python program. The urllib3 is simply a module in Python for handling ht URL in Python program. For example you can access an HTTP URL on Internet and download the data from that URL. This makes development of Python program which calls the URL in much easier way. You can use the urlopen() function of this library to fetch the data from an URL in Python program.

What are the features of urllib3?

The urllib3 is powerful Python library for interacting with the HTTP server. Here are the features of the urllib3 library:

  • This library comes with the thread safety features.
  • The connection pooling is supported.
  • If you connect to the SSL then it provides client side SSL/TLS verification.
  • The urllib3 library supports file uploads with multipart encoding.
  • It comes with the feature of retrying http requests and also deals with the HTTP redirects.
  • It also supports encoding like gzip, deflate and brotli encoding.
  • It also comes with the support for HTTP and SOCKS proxies.
  • The code is 100% tested with the testing coverage of 100%. This library is robust library for working with the HTTP servers.

The urllib3 is an easy to use library which can be used in python program just importing the urllib3 package. 

What are the modules of urllib3 library?

The urllib3 library comes with many modules which makes the HTTP programming easy for Python developers. Here are the features of urllib3 library:

  • urllib.request module is used for opening and reading the data fro HTTP stream
  • urllib.parse module is used for parsing the URLs
  • urllib.error module is used for error and exceptions handling
  • urllib.robotparser is used for parsing the robot.txt file while reading a website.

All these modules of the library allows the developers to write Python program that interacts with the HTTP server.

How to download and install urllib3 library in Python?

The pip installer can be easily used to install the urllib3 library in your Python environment. Here is the command to install ulllib3:

pip install urllib3

The pip utility will download the urllib3 required files and then run the installation. Above command will install urllib3 module on your Python environment.

Examples of urllib3 module in Python

The urllib3 is powerful module in Python which is used to get data, post data, stream data, interact with HTTP server with HTTP command and use redirects. This library can also be used to work with JSON request and responses.

Check the version of urlib3 installed on the machine. First of all we will check the version of urllib3 library installed in the Python environment, for this open the Python terminal and then run  following program:


import urllib3
print(urllib3.__version__)

Here is the output of program:


[email protected]:~$ python
Python 3.7.0 (default, Jun 28 2018, 13:15:42) 
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3
>>> print(urllib3.__version__)
1.23 

Above code shows the version of urllib3 module installed on my machine and it is 1.23. Now it is confirmed that urllib3 is correctly installed on my computer and it can be used for programming. Here is the screenshot of the program tested on Ubuntu 18.04 system:

Python urllib3 version

Here is simple example to get the data from HTTP server using GET HTTP method. Following example code reads the data from website and then prints the html code returned from the server:


import urllib.request 
request = urllib.request.urlopen('https://www.python.org/') 
print(request.read())

Above code reads the data from python.org website and then prints the data. Here is the screen shot:

Python urllib3 http get example

Check more tutorials at:

Ads

Ads