Shipping Python APIs/
Lesson

Your AI assistant just helped you build a FastAPI application. It works perfectly on localhost. Now you type "how do I deploy this?" and get a confident recommendation for a platform. But AI picks platforms the way it picks variable names, based on what it has seen most often, not based on your specific constraints. This lesson gives you the framework to evaluate that recommendation.

The deployment landscape for Python

Python APIs cannot run on purely static hosting platforms like GitHub Pages or Netlify (those serve HTML/JS only). You need a platform that runs a Python process, specifically, a WSGI or ASGI server like uvicorn or gunicorn.

The good news: in 2026, several platforms make this nearly painless. The bad news: "nearly painless" still requires understanding what is happening under the hood, because when something breaks at 2 AM, the AI is not the one getting paged.

02

Railway

Railway is the platform AI recommends most often, and for good reason, it has the shortest path from code to deployed URL.

# The entire Railway deployment flow
railway login
railway init
railway up
# That's it. You get a URL.

Railway detects your Python project, installs dependencies from requirements.txt, and runs your start command. You can also deploy from a GitHub repo with automatic deploys on push.

StrengthLimitation
Zero-config deploymentLimited free tier (500 hours/month, then $5/month)
Built-in PostgreSQL, RedisNo multi-region by default
Environment variables UICold starts on free tier
GitHub integrationLess control over infrastructure
AI pitfall
AI often shows Railway deployment without mentioning the Procfile or start command. If your project does not have a Procfile with web: uvicorn main:app --host 0.0.0.0 --port $PORT, Railway may not know how to start your app. Always verify the start command.
03

Fly.io

Fly.io deploys DockerWhat is docker?A tool that packages your application and all its dependencies into a portable container that runs identically on any machine. containers to edge locations worldwide. It gives you more control than Railway but requires more configuration.

fly launch          # generates fly.toml and Dockerfile
fly deploy          # builds and deploys
fly secrets set DATABASE_URL=postgresql://...

Fly.io generates a fly.toml configuration file and expects a Dockerfile. If you followed the Docker moduleWhat is module?A self-contained file of code with its own scope that explicitly exports values for other files to import, preventing name collisions., you already have one.

StrengthLimitation
Global edge deployment (30+ regions)Requires Docker knowledge
Persistent volumes for SQLiteMore complex setup than Railway
Built-in metrics and logsFree tier limited to 3 shared VMs
Fly Postgres (managed)Pricing can surprise you (egress costs)
04

Render

Render positions itself as the simple PaaSWhat is paas?Platform as a Service - a managed hosting service where you push your code and the platform handles deployment, SSL, restarts, and scaling., somewhere between Railway's zero-config approach and Fly.io's DockerWhat is docker?A tool that packages your application and all its dependencies into a portable container that runs identically on any machine.-based control.

yaml
# render.yaml - Infrastructure as Code
services:
  - type: web
    name: my-api
    runtime: python
    buildCommand: pip install -r requirements.txt
    startCommand: uvicorn main:app --host 0.0.0.0 --port $PORT
    envVars:
      - key: DATABASE_URL
        fromDatabase:
          name: my-db
          property: connectionString

databases:
  - name: my-db
    plan: free
StrengthLimitation
Infrastructure as code (render.yaml)Free tier spins down after 15 min inactivity
Auto-scaling on paid plansCold starts on free tier (30-60 seconds)
Managed PostgreSQL and RedisSlower builds than Railway
Preview environments per PRLimited regions (US/EU only)
05

Cloudflare Python Workers

Since 2025, Cloudflare supports Python Workers via Pyodide (a WebAssembly Python runtimeWhat is runtime?The environment that runs your code after it's written. Some languages need a runtime installed on the machine; others (like Go) bake it into the binary.). You can even run FastAPI on it. But it comes with significant constraints.

# worker.py - FastAPI on Cloudflare Workers
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Running on the edge"}

# Deployed via wrangler, runs in V8 isolates
StrengthLimitation
Global edge (300+ locations)Not all Python packages work (no C extensions)
Generous free tierCold starts for Python Workers
D1 database integrationPyodide runtime has memory limits
No Docker neededEcosystem is young, fewer examples
Good to know
Cloudflare Python Workers are a viable option for simple APIs, but for projects using SQLAlchemy, psycopg2, or other C-extension packages, you will need a traditional platform like Railway or Fly.io. The Pyodide runtime cannot load compiled C libraries.
06

Decision framework

ScenarioBest fitWhy
Hobby project, learningRailway (free tier)Fastest to deploy, good for experimentation
Startup MVP, < 1000 usersRailway or RenderLow ops burden, reasonable pricing
Need global low latencyFly.ioMulti-region edge deployment
Enterprise with complianceAWS ECS / GCP Cloud RunFull control, audit logs, VPC
Simple API, no C depsCloudflare WorkersEdge performance, generous free tier
ML model servingRailway or Fly.ioGPU support, larger instance sizes
07

Quick reference

PlatformDeploy methodDatabaseFree tierBest for
RailwayGit push / CLIBuilt-in Postgres500 hrs/monthQuick deploys
Fly.ioDocker / CLIFly Postgres3 shared VMsGlobal edge
RenderGit / render.yamlManaged PostgresSpins downPaaS simplicity
CloudflareWrangler CLID1 (SQLite)100K req/dayEdge APIs
AWS ECSDocker / TerraformRDS12-month trialEnterprise