Learning FastAPI works best when you launch a real server early. FastAPI turns Python functions into HTTP APIs. uv bootstraps the project folder and manages dependencies. uvicorn binds the FastAPI app to HTTP. Holding onto the "focus on the core flow" rule from part 1, this post stays with installation and the very first run so later posts can jump straight to parameters. If uv is new to you, install it from the official instructions or fall back to pip + python -m venv; the rest of the steps translate directly.
Key terms
- uv – a lightweight package/environment manager (think "pip + virtualenv" in one tool) that initializes Python projects and runs commands. Every command in this post uses it.
- ASGI – the async server interface standard that lets uvicorn run FastAPI apps.
- Swagger UI – the automatically generated API docs at
/docsonce FastAPI is running.
Practice card
- Estimated time: 30 minutes
- Prereqs: Python 3.12,
uvinstalled, VS Code or any terminal- Goal: create a FastAPI project with
uvand start the dev server
This walkthrough targets FastAPI ≥ 0.111 (for the built-in CLI) and uv ≥ 0.2.0. If you prefer pip, just replace uv add ... with pip install ... and run commands inside your virtualenv by prefixing them with python -m or uvicorn directly.
Getting started checklist
- Start a FastAPI project with
uv - Create the simplest API file
- Check both the JSON response and the docs page in a browser
Setup
Assuming uv is already installed (uv --version should print a version number), create a project folder.
uv init my-fastapi-app
cd my-fastapi-app
Install packages
uv add fastapi --extra standard
The --extra standard bundle installs FastAPI, uvicorn, and helpful dev dependencies (such as the docs stack). If you skip the extra, add uvicorn manually with uv add uvicorn so the server command works later.
What uvicorn does
Keep the roles straight:
FastAPIdefines endpoints and validation rules.uvicornis the ASGI server that exposes those endpoints over HTTP.
Think of ASGI as the handshake async Python web servers follow. When the browser makes a request, the flow looks like this:
Browser -> uvicorn -> FastAPI app -> JSON response
If that still feels abstract, this diagram is enough for now:
Having app = FastAPI() in main.py is not enough. You still need a server that opens a port, listens for requests, and calls that app. uvicorn is the engine that does exactly that. Even when you run uv run fastapi dev main.py, the logs say Uvicorn running on ... because that command wraps a uvicorn dev server under the hood.
If your reader does not render D2 diagrams, picture the same flow as plain text: the browser sends an HTTP request to uvicorn, uvicorn invokes your FastAPI app, the app returns a dict/list, and uvicorn sends that JSON back to the browser.
Build the first app
Create main.py.
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"message": "Hello FastAPI"}
@app.get("/items")
def read_items():
return [
{"id": 1, "name": "Pencil"},
{"id": 2, "name": "Notebook"},
]
Flow recap:
- Instantiate the app with
FastAPI(). - Register routes with
@app.get(...). - If you return built-in types such as
dictorlist, FastAPI serializes them to JSON automatically (you can customize this later with response classes).
Run the dev server
uv run fastapi dev main.py
Breakdown:
uv run– execute within the project environment.fastapi dev– start the FastAPI dev server (uses uvicorn beneath).main.py– file containing the app.
When it succeeds you should see something like:
INFO: Uvicorn running on http://127.0.0.1:8000
Heads-up:
fastapi devships with FastAPI 0.111+. If the CLI is unavailable, runuv run uvicorn main:app --reloadinstead.
Verify in the browser
Basic response
Open http://127.0.0.1:8000/ to see:
{"message":"Hello FastAPI"}
Docs pages
FastAPI also gives you docs instantly:
http://127.0.0.1:8000/docshttp://127.0.0.1:8000/redoc
In /docs you can press buttons to send actual requests.
💬 댓글
이 글에 대한 의견을 남겨주세요