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.
/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.
| Variable | Example value | Note |
|---|---|---|
| DATABASE_URL | postgresql+asyncpg://user:pass@host:5432/db | Used by SQLAlchemy / databases. Omit if the preview does not need a real DB. |
| SECRET_KEY | replace-me-32-char-random-string | For JWT / session signing if your app uses it. Any long random string works for previews. |
| ENVIRONMENT | preview | Optional — 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
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
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
*.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
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?
/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