Series



SQLite From Scratch Using Python

A series of posts covering fundamental concepts in SQLite

This series covers Building a small SQLite (a file based database) from scratch using python.

Ever wondered what’s actually happening when you run SELECT * FROM users? Databases often seem like magical black boxes, but they’re ultimately just carefully organised files on a disk. In this series, we’ll pull back the curtain by building our own simplified database engine compatible with SQLite.

Why SQLite? It’s brilliant in its simplicity—a single file that contains an entire relational database. No servers to configure, no complex setup. Just a file that somehow manages to store structured data with impressive efficiency.

Why Build a Database? Aren’t There Enough Already?

Fair question. We’re not trying to replace SQLite or PostgreSQL here. This is about understanding. Building a database from scratch will:

  1. Demystify the Magic: Transform databases from mysterious black boxes into understandable systems
  2. Master File I/O: Get practical experience with the nitty-gritty of reading and writing bytes
  3. Explore Data Structures: See how clever structures like B-trees make data retrieval blazingly fast
  4. Level Up Your Python: Take on a substantial project that will sharpen your programming skills

By the end of this series, you’ll never look at a database the same way again. The next time you execute a query, you’ll have a mental model of what’s happening under the hood.

Posts in this series:

  • Part 6: Error Handling and Record Deletion - WIP
  • Part 5: SELECT Statements and WHERE Clauses - WIP
  • Part 4: From Bytes to SQL - WIP
  • Part 3: Cells, B-Trees, and Reading Your First Records - WIP
  • Part 2: Pages and B-Trees- The Building Blocks of Our Database - WIP
  • Part 1: The Art of Data Storage in Database- The Database Header - WIP
  • Part 0: From Linked Lists to B-Trees - Data Structures for SQLiteBD - WIP