k3forx / fastapi-todo-app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fastapi-todo-app

ライブラリなどのバージョン

バックエンド (Python)

  • Python: 3.9.x
  • FastAPI (フレームワーク): v0.65.2

フロント (CSS と JavaScript)

  • bootstrap: v5.0.2

仮想環境の構築

公式ドキュメントにしたがって仮想環境を構築していきます。

まずは現状の python のバージョンをチェックしましょう。

❯ python -V
Python 2.7.16

❯ python3 -V
Python 3.9.5
❯ python3 -m venv venv

❯ ls
README.md  venv

❯ source venv/bin/activate

❯ python -V
Python 3.9.5

❯ python3 -V
Python 3.9.5

❯ deactivate

❯ python -V
Python 2.7.16

❯ python3 -V
Python 3.9.5

FastAPI で Hello World

from fastapi import FastAPI

app = FastAPI()


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

起動する。

❯ uvicorn main:my_app --reload

http://localhost:8000 にアクセスする。

image

さらに http://localhost:8000/docs にアクセスする。 image

Unit test

❯ pytest -vvvs --cov=./ --cov-config=../.coveragerc --cov-report=term-missing unit_test --disable-pytest-warnings

ORM

https://docs.sqlalchemy.org/en/14/tutorial/engine.html

データベースの設定

Docker で MySQL で

Prometheus

❯ curl -X POST http://localhost:9090/-/reload

FastAPI by Docker

❯ docker build ./app -t fastapi-todo-app

❯ docker images | grep fastapi-todo-app
fastapi-todo-app                     latest    2bf123e25958   2 minutes ago    184MB

About


Languages

Language:Python 97.3%Language:Dockerfile 2.7%