webmaster-kazu.com

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

APIを構築するための最新の高速Webフレームワーク「fastapi」をインストールする

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

APIを構築するための最新の高速、高性能なWebフレームワーク「fastapi」のインストールについて解説しています。

fastapi(https://github.com/tiangolo/fastapi)のライブラリは、Python 3.6以降で使用することができます。

■Python

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

■fastapiをインストールする

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

pip install fastapi

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

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、pipを使う場合にはコマンドでの切り替えを行います。

py -3.8 -m pip install fastapi

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

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

Collecting fastapi

Downloading fastapi-0.68.1-py3-none-any.whl (52 kB)

|████████████████████████████████| 52 kB 318 kB/s

Collecting starlette==0.14.2

Downloading starlette-0.14.2-py3-none-any.whl (60 kB)

|████████████████████████████████| 60 kB 1.9 MB/s

Collecting pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2

Downloading pydantic-1.8.2-cp38-cp38-win_amd64.whl (2.0 MB)

|████████████████████████████████| 2.0 MB 1.3 MB/s

Requirement already satisfied: typing-extensions>=3.7.4.3 in c:\users\user_\appdata\roaming\python\python38\site-packages (from pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2->fastapi) (3.7.4.3)

Installing collected packages: starlette, pydantic, fastapi

Successfully installed fastapi-0.68.1 pydantic-1.8.2 starlette-0.14.2

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

なお、今回はfastapiのバージョン0.68.1をインストールしました。