How To Install aiohttp In Python

In Python crawlers, if you want to require concurrent HTTP requests, you typically use the python requests module. But the python requests module are synchronous libraries, if you want to send asynchronous requests you need to install the python aiohttp library.

The aiohttp is an HTTP framework based on asyncio, which can implement asynchronous requests. This article will introduce how to install the python aiohttp module.

1. What Is The Python aiohttp Library.

  1. Asyncio can implement single thread concurrent IO operation, which is a common asynchronous processing module in Python.
  2. Aiohttp is an HTTP framework based on asyncio. It can help us to implement HTTP requests asynchronously, which greatly improves the efficiency of our program.

2. How To Install aiohttp In Python.

  1. Run the command pip show aiohttp to check whether the python aiohttp module has been installed or not.
    $ pip show aiohttp
    WARNING: Package(s) not found: aiohttp
  2. From the above output, we can see that the python aiohttp module does not exist, so we should run the command pip install aiohttp to install it.
    $ pip install aiohttp
    Collecting aiohttp
      Downloading aiohttp-3.7.4.post0-cp37-cp37m-macosx_10_14_x86_64.whl (644 kB)
         |████████████████████████████████| 644 kB 631 kB/s 
    Collecting yarl<2.0,>=1.0
      Downloading yarl-1.6.3-cp37-cp37m-macosx_10_14_x86_64.whl (123 kB)
         |████████████████████████████████| 123 kB 9.5 MB/s 
    Collecting typing-extensions>=3.6.5
      Downloading typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
    Requirement already satisfied: attrs>=17.3.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from aiohttp) (20.3.0)
    Collecting async-timeout<4.0,>=3.0
      Downloading async_timeout-3.0.1-py3-none-any.whl (8.2 kB)
    Requirement already satisfied: chardet<5.0,>=2.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from aiohttp) (3.0.4)
    Collecting multidict<7.0,>=4.5
      Downloading multidict-5.1.0-cp37-cp37m-macosx_10_14_x86_64.whl (49 kB)
         |████████████████████████████████| 49 kB 2.0 MB/s 
    Requirement already satisfied: idna>=2.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from yarl<2.0,>=1.0->aiohttp) (2.8)
    Installing collected packages: typing-extensions, multidict, yarl, async-timeout, aiohttp
    Successfully installed aiohttp-3.7.4.post0 async-timeout-3.0.1 multidict-5.1.0 typing-extensions-3.7.4.3 yarl-1.6.3
  3. After the installation, you can test it from the python command line with the import aiohttp code line like below, if there are no errors it means the installation was successful.
    $ python
    Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) 
    [Clang 6.0 (clang-600.0.57)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    >>> import aiohttp
    >>>

Reference

  1. PyPI aiohttp website.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.