uv is a Python tool for managing virtual environments and dependencies. It simplifies the process of creating and managing Python projects.

# Install uv if needed
$ curl -LsSf https://astral.sh/uv/install.sh | sh

or

$ sudo snap install astral-uv --classic
astral-uv 0.12.21 from Alex Lowe (lengau✪) installed

# Create and enter the project
$ uv init my-sample-api --bare
~/workspace/python/my-sample-api`

$ cd my-sample-api

# Add FastAPI and its standard dependencies
$ uv add "fastapi[standard]"
Using CPython 3.12.3 interpreter at: /usr/bin/python3
Creating virtual environment at: .venv
Resolved 58 packages in 297ms
Installed 56 packages in 11ms
 + agent-detector==2.0.0
 + annotated-doc==0.0.5
 + annotated-types==0.8.0
 + anyio==4.15.1
 + certifi==2026.7.22
[snip]

# Create the app file
$ cat > main.py <<'EOF'
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
return {"message": "Hello, world!"}
EOF

# Run the development server
uv run fastapi dev main.py

If you see an error:

╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│  /home/milesd-9510/workspace/python/my-sample-api/main.py:7                                                             │
│ return {"message": "Hello, world!"}                                                                                     │
│ ▲                                                                                                                       │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Make sure you have the correct indentation for the return statement:


from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Hello, world!"}

The successful startup output for FastAPI should look like this:

$ uv run fastapi dev main.py

 ⚡️ Starting FastAPI in development mode

 🐍 Using import string: main:app

 🌐 Server started at http://127.0.0.1:8000
    Documentation at http://127.0.0.1:8000/docs

  Logs:

 ▕  Will watch for changes in these directories: ['/home/milesd-9510/workspace/python/my-sample-api']
 ▕  Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ▕  Started reloader process [27143] using WatchFiles
 ▕  Started server process [27145]
 ▕  Waiting for application startup.
 ▕  Application startup complete.