LoginSignup
0
0

Poetryを使用してFast APIを動かしてみる

Last updated at Posted at 2024-05-08

ファイル構造

fast-api/
├── app
│  ├── init.py
│  └── main.py
├── poetry.lock
└── pyproject.toml

pyproject.toml作成

$ poetry init
色々出てくるが、エンター押し続けてればOK

必要なパッケージをインストール

$ poetry add fastapi
$ poetry add "uvicorn[standard]"

poetry.lock作成

$ poetry install --no-root

main.pyを編集

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def hello():
return {"message" : "Hello,World"}

FastAPI起動

$ poetry run app.main:app --host 0.0.0.0 --port 80 --reload

起動しているか確認

・API ドキュメント(Swagger UI)
http://localhost/docs
・代替の API ドキュメント
http://localhost/redoc

参考:

Fast API 入門
https://zenn.dev/sh0nk/books/537bb028709ab9/viewer/742f63
FastAPIとは?PythonのWebフレームワークでWebAPIを開発しよう!
https://aiacademy.jp/media/?p=988

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