What is FastAPI? FastAPI is a modern Python framework used for building APIs. It is known for:
- Built on ASGI instead of WSGI
- Uses Starlette (fast async networking)
- Uses Pydantic for ultra-fast validation
- Benchmarks close to Node.js and Go
Go to:
http://localhost:8000/docs
You get full API docs automatically.
Pydantic models ensure that every request is validated.
Built for async/await.
uv initThis creates:
pyproject.toml
README.md
.python-version
uv.lock
main.py
uv add "fastapi[standard]"This installs:
- FastAPI
- Uvicorn
- Pydantic
- Starlette
- Other required extras
Inside your project directory, create these folders:
fastapi-demo/
│
├── src/
│ ├── app/
│ │ ├── main.py
│ │ ├── models/
│ │ ├── routes/
│ │ ├── schemas/
│ │ ├── database/
│ │ ├── core/ # config, settings, security
│ │ ├── utils/
│ │ └── __init__.py
│ └── ...
│
├── pyproject.toml
└── README.md
Create:
src/app/main.py
Write:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def home():
return {"message": "Hello FastAPI!"}Run the app via uv:
uv run uvicorn src.app.main:app --reloadWith Port:
uv run uvicorn src.app.main:app --reload --port 8000Open in browser:
http://localhost:8000
http://localhost:8000/docs
FastAPI environment is now correctly set up.