3
3

More than 1 year has passed since last update.

FastAPIのリモートデバッグ設定(VSCode、debugpy)

Last updated at Posted at 2021-08-19

記載内容

FastAPIについて、VSCodeとdebugpyを使ったリモートデバッグ方法を記載します。

FastAPIは下記のように起動します。これでどうやって、main.pyにリモートデバッガーを接続できるのか迷ったので、記録を残します。

uvicorn main:app --reload

FastAPIの起動方法

単純にuvicornをモジュールとして実行する形で、main.pyをリモートデバッグできました。

python -m debugpy --listen 0.0.0.0:5678 --wait-for-client -m uvicorn main:app --reload

VSCodeのlaunch.jsonの設定

通常通り設定すればOKです。

{
    "version": "0.1.0",
    "configurations": [
        {
            "name": "FastAPI Remote Debug",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "/hogehoge"
                }
            ]
        }
    ]
}
3
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3