FastAPI + CUBRID API Service Template¶
Overview¶
Production-ready starter template for building REST APIs with FastAPI, SQLAlchemy 2.0, and CUBRID 11.2. It is intentionally lean: sync SQLAlchemy session lifecycle, clean repository pattern, and Docker-first local setup.
Quick Start¶
- Copy this template and move into the directory.
- Create your environment file:
- Start services:
- Open:
- API:
http://localhost:8000 - Swagger UI:
http://localhost:8000/docs - Health:
http://localhost:8000/health
Project Structure¶
app/
├── main.py # FastAPI app factory, lifespan, CORS
├── config.py # pydantic-settings based configuration
├── database.py # SQLAlchemy engine/session/base
├── models.py # cookbook_items, cookbook_categories
├── schemas.py # Request/response models
├── crud.py # Repository pattern CRUD logic
└── routes/
├── health.py # GET /health
└── items.py # Item CRUD endpoints
API Endpoints¶
GET /health→{"status": "ok", "database": "connected"}GET /items?skip=0&limit=20→ paginated item listGET /items/{item_id}→ single itemPOST /items→ create itemPUT /items/{item_id}→ update itemDELETE /items/{item_id}→ delete item
Configuration¶
Environment variables (see .env.example):
DATABASE_URL(defaultcubrid+pycubrid://dba@cubrid:33000/testdb)APP_HOST(default0.0.0.0)APP_PORT(default8000)
Additional settings in app/config.py:
APP_NAMEDEBUGCORS_ORIGINS
Development¶
- Tables are auto-created at startup via
Base.metadata.create_all(). - SQLAlchemy access is fully parameterized through ORM/query builder usage.
- Keep this template starter-focused: no auth, no migrations, no framework over-abstraction.
- Run locally without Docker:
- Do not add
index=Trueto primary key columns: CUBRID rejects a second index on columns a primary key orUNIQUEconstraint already indexes, socreate_all()fails at startup. - Each recipe under
recipes/ships a test suite that runs against live CUBRID whenCUBRID_TEST_URLis set and falls back to in-memory SQLite otherwise. See the Test section of each recipe's README.