Skip to content

PRO TIP Block youtube.com at the DNS level β€” Pi-hole, NextDNS or your hosts file β€” but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Python Backend #3: Connect Flask to a Database (SQLite CRUD Tutorial)

1.9K views on YouTube

πŸ“¦ Persist your data with SQLite!
In this video, we connect our Flask API to a real database using SQLite. You’ll learn how to create a products.db file, write SQL queries with Python, and replace your in-memory lists with persistent storage β€” perfect for real-world apps!
Previous Project files: https://github.com/NDCSwift/Swift-Projects/raw/refs/heads/main/Python-Projects/PythonBackEnd2_app.py.zip

πŸ”§ What You’ll Learn:
βœ… How to create and connect to a SQLite database
βœ… How to create tables using raw SQL
βœ… How to replace in-memory storage with real persistence
βœ… How to use Postman to test your API

πŸ›  Tools Used:
Python 3
Flask
SQLite (built-in)
VS Code
DB Browser for SQLite https://sqlitebrowser.org/

Postman or curlπŸ”₯ Download My Project Files
πŸ‘‰ Get the source code here:
πŸ”— https://ndcswift.github.io/Swift-Projects/

⏱️ Timestamps:
00:00 – Intro
01:12 – SQLite
01:31 – Creating a database connection
02:51 – Defining our product table
06:33 – Rewriting the POST route
08:55 – Rewriting the GET route
10:14 – Testing everything with Postman
15:00 – Moving your Data base
16:02 – SQLite browser
16:28 – Updating database connection (After moving file)
18:05 – Recap & what’s next