0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCodeでFastAPIをステップ実行

0
Last updated at Posted at 2026-01-12

Udemyの講座や書籍を参考にFastAPIの基本について少しだけ勉強してみました。
ただ、講座の中ではVSCodeでデバッグする方法の説明がなく少し戸惑ったので
私のような初心者の方のお役に立つかもしれないと思い、手順を記事にしておきます。

使用環境

  • Windows11 Home 24H2
  • WSL(Ubuntu 24.04.3 LTS)
  • VSCode: 1.108.0
  • uv 0.8.22
  • Python 3.13.7
  • fastapi 0.128.0
  • uvicorn[standard] 0.40.0

VSCodeでFastAPIをデバッグ実行する手順

1. 虫マーク(実行とデバッグ) → 「launch.jsonファイルを作成します」のリンクをクリック
デバッグ1_実行とデバッグボタン.png

2. 「その他」→「Python Debugger 個のオプション」を選択
→ 個って?個別のこと?
デバッグ2_PythonDebugger.png

3. 「Python Debugger: FastAPI」を選択
デバッグ3_PythonDebugger_FastAPI.png

4. port番号"justMyCode": trueを追記

"justMyCode": true
この設定があると、以下のような動作になります

  • 自分が書いた .py ファイルの中だけでブレークポイントが有効になる
  • ライブラリ(例:FastAPI、uvicorn、requestsなど)の内部コードにはステップインしない
  • スタックトレース(エラーの出力)も自分のコード中心になる

デバッグ4_launch_json.png

5. 実行とデバッグ▷で起動
デバッグ5_デバッグの開始.png

6. ターミナルを確認し、ブラウザでアクセス
http://127.0.0.1:8001/docs
にアクセスすると API ドキュメントが開きます。
このドキュメントから各APIを実行可能です。
(呼び出し元のプログラムを作成する必要なし!)
デバッグ6_ターミナル.png

これでブレークポイントの利用やステップ実行が可能に👏

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?