FastAPI + Poetry + Uvicorn. Health endpoint, CORS, logging, optional Docker/Compose.
Updated: 9 Oct 2025
This repository is a starter pack. Don’t clone it for your project.
Create your own repository from this template, or bootstrap from scratch using the steps below.
- Click Use this template → Create a new repository in your org/user.
- Clone your new repository.
- Follow Run locally and Deploy below.
# 1) Project
mkdir my-api && cd my-api
poetry init -n
# 2) Dependencies
poetry add fastapi uvicorn[standard] pydantic-settings
poetry add --group dev pytest httpx
# 3) App skeleton
mkdir -p app
cat > app/main.py <<'PY'
from fastapi import FastAPI
from pydantic_settings import BaseSettings
from starlette.middleware.cors import CORSMiddleware
import logging, os
class Settings(BaseSettings):
APP_NAME: str = "team-starter-fastapi"
ALLOW_ORIGINS: str | None = os.getenv("ALLOW_ORIGINS") # comma-separated
settings = Settings()
app = FastAPI(title=settings.APP_NAME)
# CORS (comma-separated origins or '*' for demo use only)
origins = ["*"] if (not settings.ALLOW_ORIGINS) else [o.strip() for o in settings.ALLOW_ORIGINS.split(",")]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
log = logging.getLogger("uvicorn")
@app.get("/health")
def health():
return {"ok": True}
PY
# 4) Example env file
cat > .env.example <<'ENV'
APP_NAME=Since AI FastAPI
# e.g. http://localhost:3000 or https://your-frontend.app
ALLOW_ORIGINS=*
ENV
# 5) Run (dev)
poetry run uvicorn app.main:app --reload --port 8000
# open http://localhost:8000/health
cp .env.example .env # optional; pydantic-settings reads env
poetry install # if pyproject exists
poetry run uvicorn app.main:app --reload --port 8000
Common test utilities (add later if you want):
poetry run pytest -q
app/
main.py # FastAPI app + CORS + /health
.env.example # env hints (do not commit real secrets)
pyproject.toml # created by Poetry
Dockerfile (minimal)
FROM python:3.11-slim
WORKDIR /app
COPY app/ app/
RUN pip install fastapi uvicorn[standard] pydantic-settings
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
docker-compose.yml (optional pg + adminer)
version: "3.9"
services:
api:
build: .
ports: ["8000:8000"]
environment:
- APP_NAME=Since AI FastAPI
- ALLOW_ORIGINS=*
pg:
image: postgres:16
environment:
POSTGRES_PASSWORD: dev
POSTGRES_USER: dev
POSTGRES_DB: dev
ports: ["5432:5432"]
adminer:
image: adminer
ports: ["8080:8080"]
- Build image using the Dockerfile above, or run
uvicorn
with a process manager. - Set environment variables from
.env.example
in your platform settings. - Health check:
GET /health
→{ "ok": true }
- Keep pull requests small; use Conventional Commits.
- Do not commit secrets; use platform envs or
.env
locally. - Add routers, models, and tests as your app grows.
License: MIT