PreviewDrop for FastAPI

Deploy previews for FastAPI apps

Push a branch, get a live preview URL — including interactive /docs. PreviewDrop builds your FastAPI container and posts the link to the pull request, usually within a couple of minutes.

TL;DR
Connect your repo, push. PreviewDrop detects FastAPI, builds the image and posts a TLS-terminated PR preview URL with Uvicorn running on the other end. The interactive /docs and /redoc endpoints work out of the box — useful for sharing API previews with non-engineers.

What the build needs to do

You don't write this. PreviewDrop detects FastAPIfrom your repo and builds the container for you — a Dockerfile in your repo is not used. The reference below shows the install, build and start steps a working FastAPI image needs. If detection gets one wrong, set the matching Install, Build or Start command in Project Settings. Your app must listen on $PORT.

Reference (not read by PreviewDrop)
FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 CMD sh -c "uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000}"

Environment variables

Set these in the Variables tab of your PreviewDrop project. They're encrypted at rest and injected into every preview container at start.

VariableExample valueNote
DATABASE_URLpostgresql+asyncpg://user:pass@host:5432/dbUsed by SQLAlchemy / databases. Omit if the preview does not need a real DB.
SECRET_KEYreplace-me-32-char-random-stringFor JWT / session signing if your app uses it. Any long random string works for previews.
ENVIRONMENTpreviewOptional — lets your app detect it is running as a preview and adjust behaviour.

Common gotchas

Bind to 0.0.0.0, not 127.0.0.1

Uvicorn defaults to 127.0.0.1 which is only reachable inside the container. Make sure your Start command uses --host 0.0.0.0 so the port is reachable from outside. Without this the preview URL returns a connection refused error.

Run Alembic migrations at container start

If you use Alembic, run migrations before Uvicorn starts. Set the Start command in Project Settings to: sh -c "alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port $PORT". Preview containers start fresh each build — migrations don't persist unless you point at an external database.

CORS origins change per preview

If a separate frontend calls your API, the preview URL changes on every push. Use a permissive CORS policy for preview containers (e.g. allow *.previews.previewdrop.dev), or read allowed origins from an env var you set as a project variable in PreviewDrop.

Replace main:app if your entrypoint is different

The reference Start command uses main:app — the app FastAPI instance in main.py. Adjust to match your project structure: app.main:app for a package layout, src.api:app etc.

Why not Vercel or Netlify?

Vercel's Python runtime runs FastAPI via ASGI adapters, but with a 10-second execution limit per request. Background tasks, WebSocket endpoints, and long-running streaming responses don't fit. Netlify has no Python runtime at all. PreviewDrop runs your app in a real container: Uvicorn as a real persistent process — WebSockets, background tasks, streaming responses, and the interactive /docs endpoint all work in the PR deploy preview exactly as they do in production.

Preview your FastAPI app in 5 minutes

Connect a repo, push a branch, get a URL. No credit card, no trial clock.

Start free