DEV Community

niuniu
niuniu

Posted on

Quick Tip: Deploy a Python API on Railway's Free Tier in 4 Commands

You don't need a $5/month VPS for a small Python API. Railway's free tier gives you $5 of usage credit per month — enough to run a low-traffic Flask or FastAPI service 24/7.

Here's the whole deployment, from zero to a public URL, in 4 commands:

1. Prep the app

# main.py
from flask import Flask
app = Flask(__name__)

@app.get("/")
def hello():
    return {"status": "ok", "cost": "$0"}
Enter fullscreen mode Exit fullscreen mode
# requirements.txt
flask==3.0.0
gunicorn==21.2.0
Enter fullscreen mode Exit fullscreen mode

2. Push to GitHub

git init && git add . && git commit -m "api"
gh repo create my-free-api --public --push
Enter fullscreen mode Exit fullscreen mode

3. Deploy from the CLI

npm i -g @railway/cli
railway login
railway init          # pick "Deploy from GitHub repo"
railway up
Enter fullscreen mode Exit fullscreen mode

4. Get the public URL

railway domain
# -> my-free-api.up.railway.app
Enter fullscreen mode Exit fullscreen mode

That's it. No Dockerfile needed (Railway auto-detects Python via Nixpacks), no credit card, no server config.

The free-tier math

Railway gives $5 usage credit/month on the trial plan. A Flask app idles at ~50MB RAM. At Railway's ~$5/GB-month RAM pricing, that's roughly $0.25/month of actual usage — leaving 95% of your free credit untouched. You could run 3-4 small services on the free tier.

Free-tier alternatives compared

Platform Free tier Sleeps? Python support
Railway $5 credit/mo No Native
Render 750 hrs/mo Yes (15 min idle) Native
Fly.io 3 shared VMs No Docker
Vercel Serverless Cold starts Limited
Cloudflare Workers 100k req/day No No (JS only)

Key difference: Render's free tier sleeps after 15 minutes of no traffic — first request takes 30-50 seconds. Railway's doesn't sleep. For anything user-facing, that cold-start penalty matters.

Watch out for

  • The $5 credit is usage-based — if your app leaks memory or gets hug-of-death'd, you can burn through it. Set up usage alerts in the Railway dashboard.
  • No persistent disk on the free tier. Use a free external DB (Neon, Supabase) if you need storage.

I've been running a small webhook service this way for 3 months — total cost: $0.00, zero maintenance.

Built with the help of MonkeyCode, my current free AI coding assistant.

What's your go-to free hosting for small Python services — Railway, Render, or something else?

Top comments (0)