MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 13 as of 2026-08-23 16:15:16
  • FastAPI

Contents

  1. FastAPI
    1. main.py
    2. pip , venv steps

FastAPI

  • https://fastapi.tiangolo.com/

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.

FastAPI works OK without uv. You can build, install, and run FastAPI projects using traditional tools like pip, venv, and poetry

main.py

Install

   1 # uv An extremely fast Python package and project manager, written in Rust.
   2 # https://docs.astral.sh/uv/getting-started/installation/
   3 curl -LsSf https://astral.sh/uv/install.sh | sh
   4 pipx install uv
   5 pip install uv
   6 uv self update
   7 pip install --upgrade uv
   8 
   9 uv add "fastapi[standard]"
  10 
  11 pip install fastapi[standard]
  12 # Virtual Environment: Python's built-in venv module
  13 # Dependency Management: requirements.txt or pyproject.toml
  14 

   1 from fastapi import FastAPI
   2 
   3 app = FastAPI()
   4 
   5 @app.get("/")
   6 def read_root():
   7     return {"Hello": "World"}
   8 
   9 @app.get("/items/{item_id}")
  10 def read_item(item_id: int, q: str | None = None):
  11     return {"item_id": item_id, "q": q}

Run

uv run fastapi dev

pip , venv steps

   1 cd ~/Documents
   2 mkdir -p fastapi-test
   3 cd fastapi-test
   4 python3 -m venv .venv
   5 source .venv/bin/activate
   6 
   7 cat << 'EOF' > requirements.txt
   8 fastapi[standard]
   9 pyyamlEOF
  10 
  11 pip install -r requirements.txt 
  12 
  13 cat << 'EOF' > main.py
  14 import yaml
  15 from fastapi import FastAPI
  16 from fastapi.responses import Response
  17 
  18 app = FastAPI()
  19 
  20 @app.get("/")
  21 def read_root():
  22     return {"message": "Hello world!"}
  23 
  24 @app.get("/openapi.yaml", include_in_schema=False)
  25 def get_openapi_yaml():
  26     openapi_json = app.openapi()
  27     openapi_yaml = yaml.dump(openapi_json, sort_keys=False)
  28     return Response(content=openapi_yaml, media_type="text/yaml")
  29 
  30 EOF
  31 
  32 fastapi dev main.py
  33 # /home/vitor/Documents/fastapi-test/.venv/bin/python3 \
  34 #  /home/vitor/Documents/fastapi-test/.venv/bin/fastapi dev main.py
  35 # http://127.0.0.1:8000
  36 # Server started at http://127.0.0.1:8000
  37 # OpenAPI/Swagger documentation at http://127.0.0.1:8000/docs
  38 # http://127.0.0.1:8000/openapi.yaml
  39 # http://127.0.0.1:8000/openapi.json
  40 
  41 uvicorn main:app --reload
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01