webmaster-kazu.com

テクノロジー・データ分析・実践ログ・その他

【Python】永続的なHTTPキャッシュライブラリ「requests-cache」のインストール

カテゴリ: Python【初歩から現場実務的なもの】

【Python】永続的なHTTPキャッシュライブラリ「requests-cache」のインストールについて解説しています。

「requests-cache(https://github.com/requests-cache/requests-cache,https://requests-cache.readthedocs.io/en/stable/)」は、Pythonのrequestsライブラリでパフォーマンスを向上させるためのライブラリで、Webページの読み込みが高速化され、ネットワークトラフィックの削減にも寄与します。

■Python

今回のPythonのバージョンは、「3.10.9」を使用しています。(Windows11)(pythonランチャーでの確認)

■requests-cacheをインストールする

requests-cacheをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

pip install requests-cache

起動後、上記のコマンドを入力し、Enterキーを押します。

なお、今回は、pythonランチャーを使用しており、Python Version 3.10.9にインストールを行うために、バージョンの切り替えを行います。

py -3.10 -m pip install requests-cache

切り替えるために、上記のコマンドを入力し、Enterキーを押します。

Defaulting to user installation because normal site-packages is not writeable

Collecting requests-cache

Downloading requests_cache-1.1.0-py3-none-any.whl (60 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.1/60.1 kB 1.6 MB/s eta 0:00:00

Collecting cattrs>=22.2

Downloading cattrs-23.1.2-py3-none-any.whl (50 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 50.8/50.8 kB ? eta 0:00:00

Requirement already satisfied: urllib3>=1.25.5 in c:\users\user_\appdata\roaming\python\python310\site-packages (from requests-cache) (1.26.16)

Requirement already satisfied: attrs>=21.2 in c:\program files\python310\lib\site-packages (from requests-cache) (23.1.0)

Requirement already satisfied: requests>=2.22 in c:\users\user_\appdata\roaming\python\python310\site-packages (from requests-cache) (2.31.0)

Collecting url-normalize>=1.4

Downloading url_normalize-1.4.3-py2.py3-none-any.whl (6.8 kB)

Collecting platformdirs>=2.5

Using cached platformdirs-3.9.1-py3-none-any.whl (16 kB)

Requirement already satisfied: exceptiongroup in c:\program files\python310\lib\site-packages (from cattrs>=22.2->requests-cache) (1.1.1)

Requirement already satisfied: typing_extensions>=4.1.0 in c:\users\user_\appdata\roaming\python\python310\site-packages (from cattrs>=22.2->requests-cache) (4.7.1)

Requirement already satisfied: idna<4,>=2.5 in c:\program files\python310\lib\site-packages (from requests>=2.22->requests-cache) (3.4)

Requirement already satisfied: certifi>=2017.4.17 in c:\program files\python310\lib\site-packages (from requests>=2.22->requests-cache) (2023.5.7)

Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\user_\appdata\roaming\python\python310\site-packages (from requests>=2.22->requests-cache) (3.1.0)

Requirement already satisfied: six in c:\users\user_\appdata\roaming\python\python310\site-packages (from url-normalize>=1.4->requests-cache) (1.16.0)

Installing collected packages: url-normalize, platformdirs, cattrs, requests-cache

Successfully installed cattrs-23.1.2 platformdirs-3.9.1 requests-cache-1.1.0 url-normalize-1.4.3

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、requests-cacheが正常にインストールされたことになります。

なお、今回はrequests-cacheのバージョン1.1.0をインストールしました。