This project demonstrates how to build a FastAPI app connected to a MySQL database using SQLAlchemy and mysqlclient.
It uses an existing table (customers) from a typical Northwind database schema without recreating or deleting the table.
fastapi_project/ βββ app/ β βββ main.py # FastAPI app entry point β βββ database.py # SQLAlchemy DB connection β βββ models/ β β βββ customers.py # SQLAlchemy model (mapped to existing table) β βββ schemas/ β β βββ customers.py # Pydantic schema for API response β βββ crud/ β β βββ customers.py # Database queries β βββ routers/ β β βββ customers.py # API endpoint β βββ init.py βββ requirements.txt βββ README.md
git clone https://github.com/your-username/fastapi-mysql-northwind.git
cd fastapi-mysql-northwind
pip install -r requirements.txt
sudo apt install libmysqlclient-dev python3-dev
uvicorn app.main:app --reload