Skip to content
Home/Resources/Build guides/Deploy a Python API free
Build guide

Deploy a Python API for Free: FastAPI on Render, Step by Step

By Younus FardeenUpdated 3 Nov 20263 min read
Short answer

Write a small FastAPI app with one or two endpoints, pin dependencies in requirements.txt, push to GitHub and create a Render web service with the start command uvicorn main:app --host 0.0.0.0 --port $PORT. The free tier sleeps when idle but costs nothing and gives you a public HTTPS URL with automatic docs.

You will buildA public API with automatic documentation, for example a quotes or notes API that your frontend or a classmate can call.
TimeAbout 2 hours
Cost₹0 on Render's free tier
LevelBeginner (basic Python)

Tools you need

The 10 steps

01

Create the project

Make a folder, create a virtual environment (python -m venv .venv) and activate it. Install fastapi and uvicorn.

02

Write the app

Create main.py:

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="Quotes API")
QUOTES = ["Ship it.", "Measure, then improve."]

class Quote(BaseModel):
    text: str

@app.get("/quotes")
def list_quotes():
    return QUOTES

@app.post("/quotes", status_code=201)
def add_quote(q: Quote):
    QUOTES.append(q.text)
    return {"count": len(QUOTES)}

Run uvicorn main:app --reload and open /docs to see the generated documentation.

03

Add a test

Install pytest and httpx; create test_main.py that uses fastapi.testclient.TestClient to call /quotes and assert a 200. Run pytest.

04

Pin dependencies

Run pip freeze > requirements.txt. Render installs exactly what is in this file.

05

Push to GitHub

Add a .gitignore with .venv/ and __pycache__/, commit and push.

06

Create the Render service

In Render, create a new Web Service from your repository. Runtime: Python. Build command: pip install -r requirements.txt. Start command: uvicorn main:app --host 0.0.0.0 --port $PORT. Choose the free instance type.

07

Add environment variables

In the service settings add any secrets (API keys, database URLs) as environment variables, never in code. Read them with os.environ.

08

Deploy and test

Render builds and gives you an onrender.com URL. Call it: curl https://<your-service>.onrender.com/quotes. Open /docs on the live URL.

09

Add a database (optional)

Create a free Postgres on Supabase or Neon (Render's free Postgres is deleted after 30 days), store the connection string as an environment variable and use SQLModel or SQLAlchemy to replace the in-memory list.

10

Document it

Put the live URL, example requests and the test command in your README. Add a GitHub Actions workflow that runs pytest on every push.

Make it yours

  • A URL shortener API with a redirect endpoint.
  • A weather proxy that caches an external API.
  • An ML model behind /predict using scikit-learn and joblib.

Troubleshooting

ProblemFix
Service fails to startCheck the start command uses $PORT and the module name matches your file (main:app).
First request is slowFree services sleep after inactivity and take some seconds to wake. Say so in your README.
Module not foundThe package is missing from requirements.txt. Re-run pip freeze inside the virtual environment.

Frequently asked questions

Is Render free for Python APIs?

Yes. The free web service has 750 instance hours a month, sleeps after 15 minutes without traffic (the first visitor waits about a minute) and cannot send email over SMTP ports. That is fine for demos and portfolio projects.

What are alternatives to Render?

Cloudflare Workers for JavaScript APIs and Streamlit Community Cloud for Python demos. Railway, Fly.io and Koyeb no longer give new accounts a usable free tier, so do not plan a project around them.

How do I keep the API from sleeping?

Upgrade the instance, or accept the wake-up delay. Do not use uptime pingers that violate the host's terms.

Learn this with mentors

Programmes for builders and engineers with admissions open: live classes, mentors and project work.

Continue learning

Project guide · Software

Software projects

Full-stack apps with auth, tests, real-time features and CI.

Open guide →23 ideas
Free tools

Free cloud credits and hosting

Credits and always-free tiers to host real projects.

See the list →12 tools
About 3 hours

First web app with Cloudflare and Supabase

A React app with sign-in and a database, live on Cloudflare Pages.

Step by step →11 steps