Skip to content

About

This is a project to learn about Python, Fast API, and SQL

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

python-backend — Learn Python, SQL & FastAPI (with a React frontend)

A hands-on course that takes you from "I know a bit of Python and the Node.js stack" to building and shipping a real backend with Python, SQL, and FastAPI — then wiring it up to a React frontend you already know.

You learn by building one app across the whole course: DevHub, a small team workspace & knowledge base (projects, tasks, tags, notes, a blog, a book review list, and authentication).

How to use this course: open the PDF on one side and the matching chapters/chNN_.../ folder in your editor on the other. Read the chapter, then read the code and its comments. The comments are part of the lesson.


1. What you need to install

👉 Full instructions — including what each tool actually is, and install commands for macOS, Windows and Linux — are in SETUP.md. Start there if this is a fresh machine.

The short version: you only need Python 3.10+ to begin. Everything else is introduced by the chapter that needs it.

Tool Why When you need it
Python 3.10+ (with pip + venv) The backend language and its package/environment tools From Chapter 1
SQLite 3 CLI The zero-setup database used to learn SQL Chapters 4–6
Git Track your own work as you learn Recommended
Node.js + npm Runs the React frontend Chapters 15–16
PostgreSQL The production-grade database Chapter 14 only
Docker + Compose Runs the whole stack together Chapter 16 (optional)

2. One-time setup

From the repo root (python-backend/):

# 1) Create an isolated Python environment (like a project-local node_modules).
python3 -m venv .venv
# 2) Activate it — do this in EVERY new terminal.  macOS / Linux:
source .venv/bin/activate

On Windows PowerShell step 2 is .venv\Scripts\Activate.ps1 instead.

# 3) Install the backend + tooling dependencies.
pip install -r requirements.txt

You'll know the venv is active when your prompt shows (.venv). Deactivate any time with deactivate.

Then confirm everything landed correctly:

python check_setup.py

That script checks every prerequisite and prints the exact fix — for your OS — for anything missing.

Node ↔ Python analogy: python3 -m venv .venv + pip install -r requirements.txt is the rough equivalent of npm install — but the environment is a folder you activate, and dependencies are listed in requirements.txt instead of package.json.


3. Recommended VS Code extensions

Open this folder in VS Code and it will offer to install the recommended extensions (defined in .vscode/extensions.json); see SETUP.md for the full list and what each one does. The essentials are ms-python.python, ms-python.vscode-pylance, charliermarsh.ruff, and qwtel.sqlite-viewer.

Point VS Code at the venv interpreter: Ctrl/Cmd+Shift+P → "Python: Select Interpreter" → choose the one inside ./.venv. (A .vscode/settings.json is included that already does this.)


4. Running things

Part II — the SQL chapters (Chapters 4–6)

cd chapters/ch04_sql_foundations
sqlite3 devhub.db < schema.sql     # create the tables
sqlite3 devhub.db < seed.sql       # insert sample data
sqlite3 devhub.db                  # open an interactive SQL shell
#   sqlite> .tables
#   sqlite> SELECT * FROM projects;
#   sqlite> .quit

Or use the SQLite Viewer extension to click through devhub.db visually.

Part III — the FastAPI backend (app/backend)

source .venv/bin/activate           # if not already active
cd app/backend
uvicorn app.main:app --reload       # starts on http://127.0.0.1:8000

Then open http://127.0.0.1:8000/docs for interactive, auto-generated API docs (Swagger UI). The database is created and seeded automatically on first run. See app/backend/README.md for the seeded demo login and details.

Run the backend tests:

cd app/backend
pytest -q

Part IV — the React frontend (app/frontend)

Open a second terminal (leave the backend running):

cd app/frontend
npm install                         # first time only
npm run dev                         # starts Vite on http://localhost:5173

The frontend expects the backend at http://127.0.0.1:8000 (configurable via VITE_API_URL in app/frontend/.env). The backend already allows the Vite origin (http://localhost:5173) through CORS. See app/frontend/README.md.

Chapter 14 — PostgreSQL (optional, later)

Chapter 14 walks through installing PostgreSQL (per-OS instructions are in SETUP.md), creating the devhub database, and pointing the app at it via DATABASE_URL. Until then everything runs on zero-setup SQLite.

Chapter 16 — the whole stack with Docker (optional)

cd app
docker compose up --build

5. Rebuilding the PDF

The book is generated from the Markdown in docs/chapters/ by a script:

source .venv/bin/activate
python docs/build_pdf.py            # writes docs/python-backend-guide.pdf

Edit any docs/chapters/NN-*.md and re-run to regenerate the book.


6. Repository layout

python-backend/
├── README.md                      ← you are here
├── SETUP.md                       ← prerequisites & install, for macOS/Windows/Linux
├── check_setup.py                 ← verifies your machine is ready
├── requirements.txt               ← backend + tooling dependencies
├── docs/
│   ├── python-backend-guide.pdf   ← the course book (generated)
│   ├── build_pdf.py               ← regenerates the book from Markdown
│   └── chapters/                  ← Markdown source, one file per chapter
├── chapters/                      ← runnable, heavily-commented examples
│   ├── ch01_python_foundations/ … ch16_capstone/
└── app/
    ├── docker-compose.yml         ← runs the whole stack (Chapter 16)
    ├── backend/                   ← the finished FastAPI + SQL app
    └── frontend/                  ← the finished Vite + React app

7. The 16-chapter roadmap

Part Ch Title
I. Python 1 Python Foundations for Node.js Developers
2 Functions, Modules, Type Hints & Environments
3 OOP, Dataclasses, Decorators & Async
II. SQL 4 SQL Foundations (SQLite)
5 Relationships, Joins & Analytics
6 Talking to SQL from Python (SQLAlchemy)
III. FastAPI 7 FastAPI First Steps
8 Pydantic & Schemas
9 Building a CRUD API on a Database
10 Relationships, Filtering & Pagination
11 Authentication & Authorization
12 Rounding Out the API (CORS, errors, aggregation)
13 Testing & Migrations
IV. Ship it 14 Moving to PostgreSQL
15 The React Frontend
16 Capstone & Deployment

8. Track your own work with Git (recommended)

This ships as plain files, not a Git repository, so you can start your own history from the very first commit:

git init && git add . && git commit -m "Start the python-backend course"

.gitignore already excludes .venv/, node_modules/, *.db and .env, so only real source gets committed. Commit after each chapter — you'll have a record of exactly what you changed while learning.


9. Troubleshooting

Run python check_setup.py first — it diagnoses most problems automatically. The common ones:

  • ModuleNotFoundError — your venv isn't active (no (.venv) in the prompt) or you skipped pip install -r requirements.txt.
  • command not found: python — use python3 (macOS/Linux) or py (Windows). In an active venv, plain python works.
  • uvicorn: command not found — activate the venv first; uvicorn installs into it.
  • CORS error in the browser — make sure the backend is running and its allowed origins include the frontend URL (http://localhost:5173).
  • Frontend can't reach the API — check app/frontend/.env's VITE_API_URL and that the backend is up on port 8000.

A fuller table — including Windows PowerShell and Debian/Ubuntu specifics — is in SETUP.md.

Happy building — start with Chapter 1 in the PDF.

About

This is a project to learn about Python, Fast API, and SQL

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages