Resources / Hosting
How to deploy a Python API (without managing a server)
The ways to deploy a Python API — Flask or FastAPI on a VPS, containers, platforms and serverless functions — with the trade-offs and a checklist for production.
You've written an API in Python — with FastAPI, Flask, or plain functions — and it works on your laptop. Here are the ways to put it online, from most control to least effort.
1. A virtual server (VPS)
Rent a Linux server, install Python, run your app behind a production server and a reverse proxy:
# FastAPI
uvicorn main:app --host 127.0.0.1 --port 8000 --workers 2
# Flask
gunicorn -w 2 -b 127.0.0.1:8000 app:app
Put Nginx or Caddy in front for HTTPS, and a process manager (systemd) to restart it.
- Pros: cheap, full control.
- Cons: you own security updates, TLS, restarts, backups, logs and scaling.
2. A container
Package the app with a Dockerfile and run it on a container service or your own cluster.
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
- Pros: the same image runs everywhere; easy to roll back.
- Cons: you still choose sizes, scaling rules and a registry, and pay while it's idle.
3. A platform (PaaS)
Push your repo; the platform builds and runs it, with HTTPS and logs built in.
- Pros: little operations work.
- Cons: you usually pay for always-on instances; scaling settings are still yours.
4. Serverless functions
Each endpoint is a function that runs per request. No server to keep alive.
- Pros: scales automatically, costs nothing when idle, no OS to patch.
- Cons: cold starts, run-time and package-size limits, and a different shape from a long-running web app.
A production checklist (whichever you choose)
- HTTPS everywhere.
- Secrets in environment variables or a secret store — never in the repo.
- Pinned dependencies (
requirements.txtwith versions, or a lock file). - Input validation (Pydantic models in FastAPI make this easy).
- Health checks and logs you can search.
- Rate limits on public endpoints.
- A rollback path for bad deploys.
Deploying Python on Wisp
On Wisp you skip the packaging: describe the endpoint and Wisp writes it as a Python handler — or paste your own function — installs the PyPI packages it imports (locked per project), and serves it at its own HTTPS URL. It scales automatically and down to zero, with secrets, logs, rate limits, drafts and rollback built in:
def handler(req):
name = req["query"].get("name", "world")
return {"status": 200, "body": {"message": f"Hello, {name}!"}}
Each request can run for up to 15 seconds with 256 MB of memory, and packages need prebuilt wheels — the right fit for APIs, webhooks and jobs rather than long-running workers.
Build it with Wisp — describe an API, get it live.