Render is a cloud platform that runs web services straight from a Git repository. Deploying a FastAPI app on Render means pushing code to GitHub, telling Render how to build and start it, and getting a public HTTPS URL with automatic deploys on every push. We walk through each step using a small quotes API we built and tested.
Key takeaways
- Render builds and runs our code from a Git repository, so a deploy is a git push plus a small config file.
- Uvicorn must bind to 0.0.0.0 and read the port from the PORT variable, because Render assigns the port at run time.
- A render.yaml blueprint stores the whole service setup in the repo, so the service can be rebuilt from scratch.
- The free tier gives 750 instance hours a month and sleeps after 15 minutes without traffic, with a cold start of about a minute.
- A free Render PostgreSQL database expires 30 days after creation, so a long lived project needs another database.
What we build
We build a quotes API with five endpoints: a welcome message, a health check, a list of quotes, a way to add a quote, and a way to fetch or delete one quote by id. Quotes are stored in a small JSON file, which keeps the project simple and needs no database. The health check endpoint matters because Render pings it to decide whether our service is alive. We ran every command in this guide on our own machine; the dashboard steps follow Render's official docs, checked on 27 November 2026.
Prerequisites
We need Python 3.12, git, a GitHub account and a Render account; the free tier needs no card. We ran this tutorial with Python 3.12.3, FastAPI 0.162.2, Uvicorn 0.54.0 and pytest 9.2.0. Create a folder called quotes-api with a virtual environment inside it, then run pip install fastapi uvicorn.
Step 1: Write the API
Save this as main.py. It defines the app, a Pydantic model that validates each quote, and the five endpoints. The /health endpoint returns a plain status object for Render's health check. Data lives in quotes.json next to the code, loaded and saved by two small helpers.
import json
from pathlib import Path
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, Field
DATA_FILE = Path(__file__).with_name("quotes.json")
app = FastAPI(title="Quotes API", version="1.0.0")
class QuoteIn(BaseModel):
text: str = Field(min_length=1, max_length=280)
author: str = Field(min_length=1, max_length=100)
class Quote(QuoteIn):
id: int
def load_quotes() -> list[dict]:
if not DATA_FILE.exists():
return []
return json.loads(DATA_FILE.read_text(encoding="utf-8"))
def save_quotes(quotes: list[dict]) -> None:
DATA_FILE.write_text(json.dumps(quotes, indent=2), encoding="utf-8")
@app.get("/")
def root():
return {"message": "Quotes API is running", "docs": "/docs"}
@app.get("/health")
def health():
return {"status": "ok"}
@app.get("/quotes", response_model=list[Quote])
def list_quotes():
return load_quotes()
@app.post("/quotes", response_model=Quote, status_code=201)
def add_quote(quote: QuoteIn):
quotes = load_quotes()
new_id = max((q["id"] for q in quotes), default=0) + 1
record = {"id": new_id, **quote.model_dump()}
quotes.append(record)
save_quotes(quotes)
return record
@app.get("/quotes/{quote_id}", response_model=Quote)
def get_quote(quote_id: int):
for quote in load_quotes():
if quote["id"] == quote_id:
return quote
raise HTTPException(status_code=404, detail="Quote not found")
@app.delete("/quotes/{quote_id}", status_code=204)
def delete_quote(quote_id: int):
quotes = [q for q in load_quotes() if q["id"] != quote_id]
if len(quotes) == len(load_quotes()):
raise HTTPException(status_code=404, detail="Quote not found")
save_quotes(quotes)
return None
Pydantic rejects an empty quote text with a 422 response, so bad input never reaches storage. The delete endpoint returns 204 with no body, the standard answer for a successful delete.
Step 2: Pin the dependencies
Render installs dependencies from requirements.txt during the build, so the file must list everything the app imports. Save this as requirements.txt:
fastapi==0.162.2
uvicorn==0.54.0
We pin exact versions because an unpinned file can pull a new release on the next deploy and break a working service. Pydantic arrives with FastAPI, so it needs no separate line.
Step 3: Test it before you deploy
A failed deploy wastes a build cycle, so we test first. We wrote eight pytest checks with FastAPI's TestClient: root and health, an empty list, adding and reading a quote, a 404 for a missing quote, a 422 for empty text, deleting a quote, and proving quotes persist to the JSON file. The result:
test_main.py::test_root PASSED
test_main.py::test_health PASSED
test_main.py::test_empty_list PASSED
test_main.py::test_add_and_get_quote PASSED
test_main.py::test_missing_quote_404 PASSED
test_main.py::test_validation_rejects_empty_text PASSED
test_main.py::test_delete_quote PASSED
test_main.py::test_quotes_persist_to_file PASSED
8 passed in 0.66s
Then we ran the real server the way Render starts it, with the port from the environment:
export PORT=8765
uvicorn main:app --host 0.0.0.0 --port $PORT
One shell gotcha caught us here. Writing PORT=8765 uvicorn main:app --port $PORT on one line fails, because bash expands $PORT before the assignment takes effect and Uvicorn gets an empty port. Export the variable on its own line first. With the server running, we added two quotes and read them back:
$ curl -s http://127.0.0.1:8765/health
{"status":"ok"}
$ curl -s -X POST http://127.0.0.1:8765/quotes \
-H 'Content-Type: application/json' \
-d '{"text": "Simplicity is the soul of efficiency.", "author": "Austin Freeman"}'
{"text":"Simplicity is the soul of efficiency.","author":"Austin Freeman","id":1}
$ curl -s http://127.0.0.1:8765/quotes
[{"text":"Simplicity is the soul of efficiency.","author":"Austin Freeman","id":1},
{"text":"First, solve the problem. Then, write the code.","author":"John Johnson","id":2}]
The docs page at /docs returned 200 and a missing quote returned 404. The app works, so it is ready to deploy.
Step 4: Add a render.yaml blueprint
A Blueprint is a render.yaml file in the repo root that describes the service, so the whole setup lives in version control. Save this as render.yaml:
services:
- type: web
name: quotes-api
runtime: python
plan: free
region: frankfurt
buildCommand: pip install -r requirements.txt
startCommand: uvicorn main:app --host 0.0.0.0 --port $PORT
healthCheckPath: /health
envVars:
- key: ENVIRONMENT
value: production
Each field earns its place. The type is web and the runtime is python, the current field name in the Render Blueprint spec; the older env field is deprecated, so guides that still use it are out of date. The free plan gives 0.1 CPU and 512 MB of RAM, according to the same spec. We picked frankfurt as the closest region to our European readers. The healthCheckPath points at the endpoint from Step 1, so Render can tell a healthy service from a crashed one. We checked the file parses as valid YAML, since a bad indent is the most common blueprint mistake.
Step 5: Push the code to GitHub
Render deploys from a Git repository, so the code has to be on GitHub first. Add a .gitignore that keeps the virtual environment and the local quotes file out of the repo:
.venv/
__pycache__/
*.pyc
.pytest_cache/
quotes.json
Leaving quotes.json out is deliberate. Render's filesystem is ephemeral, so anything the app writes at run time vanishes on the next deploy. The JSON file suits a demo; a real service needs a database. Then commit and push to main. The repo needs main.py, requirements.txt, render.yaml and .gitignore, nothing else.
Step 6: Create the web service on Render
There are two ways to create the service. In the dashboard, click New, then Web Service, connect the GitHub repo, and pick the Python runtime. Render suggests a build command of pip install -r requirements.txt and a start command of uvicorn main:app --host 0.0.0.0 --port $PORT. Choose the Free instance type and a region, then click Create Web Service. The faster route is New, then Blueprint, pointed at the same repo: Render reads render.yaml and creates the service with every setting from Step 4, no form filling needed. Either way, Render clones the repo, installs the requirements, and starts Uvicorn. The first build takes a couple of minutes, with a live log in the dashboard. When it finishes, the service gets a URL like https://quotes-api.onrender.com.
Step 7: Check the live API
Call the live URL the same way we called the local server:
$ curl https://quotes-api.onrender.com/health
{"status":"ok"}
$ curl https://quotes-api.onrender.com/quotes
[]
Open /docs on the live URL to see the automatic API docs. Every push to main now triggers a new deploy, because Render watches the linked branch by default. That is the whole loop: change code, test it, push, and the live API updates itself.
Why does Render need the PORT variable?
Render assigns a port to each service when it starts, and the number changes between deploys. A start command that hard codes port 8000 starts Uvicorn, but Render cannot route traffic to it, so the service answers with a 502. Reading $PORT in the start command is the fix. Binding to 0.0.0.0 instead of 127.0.0.1 matters just as much: inside a container, localhost means the container itself, while Render's router sits outside it. Both mistakes show up in the deploy log as a service that starts and never answers.
Why is the first request slow on the free tier?
A free web service spins down after 15 minutes without traffic, and the next request takes about a minute to wake it up. Render grants 750 free instance hours per workspace per month, and if the hours run out, every free service in the workspace is suspended until the next month, according to Render's own free tier guide. One service running around the clock uses about 730 hours, so the allowance covers exactly one always on service. For a demo that trade off is fine; for anything real, the Starter plan costs about 7 dollars a month and never sleeps.
What breaks most first deploys?
Four things, in the order we see them most. A start command that forgets $PORT or binds to localhost. A requirements.txt missing a package the code imports, which fails the build. A render.yaml with a bad indent, which fails validation before anything builds. And a secret committed to the repo instead of set as an environment variable. Render keeps secrets in the Environment tab, and code reads them with os.environ. The deploy log names the exact failure in each case, so read it before changing code at random.
What to try next
First, swap the JSON file for a real database. A free Neon or Supabase Postgres database outlives Render's own free database, which expires 30 days after creation and is deleted after a 14 day grace period, according to Render's own free tier guide. Some third party guides still quote 90 days, but we follow Render's own page. Second, add a GitHub Actions workflow that runs pytest on every pull request, so broken code never reaches Render. Third, point a custom domain at the service from the dashboard, which takes a few minutes and makes the API look finished.
Originally published on LogicStack. Run the code examples right in your browser with our free interactive Python and SQL playgrounds — no setup, no sign-up.
Top comments (0)