LoginSignup
0
2

More than 1 year has passed since last update.

FastAPIでホットリロードを有効にする方法(2パターン)

Last updated at Posted at 2022-04-20

1. 起動オプションから指定

FastAPIでホットリロードを有効にする方法を調べると、大体こんな感じで起動オプションを設定する方法が出てきます。

$ uvicorn main:app --reload

2. uvicorn.run()で指定

コマンドラインからではなく、コード上でホットリロードを指定するには以下のようにreload=Trueを追記します。

main.py
if __name__ == '__main__':
    uvicorn.run("main:app", port=8000, reload=True)

ちなみにアクセスログの設定はaccess_log=True/Falseとすれば良いそうです。

そのまま立ち上げればOKです。

$ python main.py

uvicornパスが通らない環境(windows)等ではこの方法が良いのではないでしょうか。

参考文献

https://www.uvicorn.org/settings/
https://zenn.dev/satto_sann/articles/b405ca8961d70fac99ff

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