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.

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"]

3. A platform (PaaS)

Push your repo; the platform builds and runs it, with HTTPS and logs built in.

4. Serverless functions

Each endpoint is a function that runs per request. No server to keep alive.

A production checklist (whichever you choose)

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.

Related