# FastAPI

A FastAPI 0.115 starter in Python 3.12, served by Uvicorn, for developers who want a clean Python API skeleton with no database. It includes routes grouped with APIRouter, interactive docs at /docs and /redoc, pytest tests through TestClient and ruff linting.

- Framework: FastAPI (Python)
- Category: Starters / REST APIs
- Creates: a server app
- Plan: Free
- Price: Free
- Author: Light Cloud
- Page: https://templates.light-cloud.com/starters/rest-apis/fastapi-starter
- Updated: 2026-11-21

## Features

- GET / returns { "message": "Hello from FastAPI on Light Cloud" } from a router in app/routers/root.py
- Swagger UI at /docs, ReDoc at /redoc and the generated schema at /openapi.json
- Routers in app/routers/ are included in app/main.py, so each new module shows up in /docs
- main.py works as uvicorn main:app and as python main.py, which binds 0.0.0.0 and reads PORT (default 8000)
- pytest tests call / and /docs through FastAPI's TestClient without starting a server
- ruff configured in pyproject.toml for pyflakes, pycodestyle, import sorting, pyupgrade and bugbear rules
- Two pinned runtime dependencies: fastapi 0.115.0 and uvicorn 0.30.6

## What you need

- Free plan: it runs as a server app, and the Free plan includes 3 server apps
- To run it locally: Python 3.12 and pip, in a virtual environment
- No API keys: it starts with nothing to configure

## About

The FastAPI app is built in app/main.py and re-exported from a root main.py, so Uvicorn finds it as main:app and the same file can also start the server directly. FastAPI builds the OpenAPI schema from your routes and type hints, which means the /docs page grows as you add routers with no extra work. Runtime packages are pinned in requirements.txt and test tools in requirements-dev.txt; pyproject.toml only holds pytest and ruff settings. On Light Cloud the deploy installs requirements.txt and runs uvicorn main:app on the PORT the platform sets, and every push to your copy redeploys.

## Questions

### Is there a free FastAPI starter template?

Yes. This FastAPI starter is MIT licensed and free to copy, and it runs as one of the 3 server apps on Light Cloud's Free plan, with no card needed.

### How do I add a new endpoint in FastAPI?

Add a module in app/routers/ with its own router = APIRouter(), then call app.include_router(things.router) in app/main.py. The new routes appear in /docs straight away.

### How do I enable CORS in FastAPI?

CORS is not enabled. Add CORSMiddleware from fastapi.middleware.cors in app/main.py with app.add_middleware(CORSMiddleware, allow_origins=["https://example.com"]).

### How do I deploy a FastAPI app with a database?

This starter has none. The fastapi-postgresql-crud-api template adds PostgreSQL with psycopg 3 and a CRUD resource, and deploying it on a paid plan creates the database and sets the connection variables.

### Can I host this FastAPI app without Light Cloud?

Yes. Any host with Python 3.12 runs it: install requirements.txt and start uvicorn main:app --host 0.0.0.0 --port $PORT.
