Python FastAPI Labs

Virtual E#nvironents

Creating a virtual environment

python3 -m venv venv

Activating the virtual environment

source venv/bin/activate

Installing dependencies

pip install -r requirements.txt

FastAPI Simple example

from fastapi import FastAPI

app = FastAPI()

@app.get("/", tags=["posts"])
def list_all_posts():
    return [{ "title": "My first post", id: 1 }, { "title": "My second post", id: 2 }]

To run:

uvicorn main:app --reload

Libraries

Jinja2 for HTML templating