Your Programs Have Amnesia
Every program you have written so far forgets everything when it stops. The flashcard quiz knows your score until the run ends; the budget tracker totals your week, then the numbers are gone. That is fine for a demo and useless for a real app.
The fix is a database, and the word is less scary than it sounds. A database is data that outlives the program that wrote it, plus rules for reading it back. Your first one needs no server, no account, and no new language — just one file and four small functions.
A File Can Be a Database
The file in this article is study-log.json, a list of study sessions. Each entry has two facts: a subject and minutes. That is the whole schema — the shape every entry agrees to follow. JSON fits a first database because you can read it yourself: open the file and you see the data.
Three rules make a file a database instead of a scribble. Every entry has the same shape, so code can trust it. There is one way in, a load function, and one way out, a save function. And the program checks what it finds — a missing file means start empty, not crash.
You have met this data before: the data project article loaded quiz scores from a CSV file. This is the next step — your program writes the file itself, and reads it back next time it runs.
Try It: A Study Log That Remembers
Paste it into the browser editor and run it. It logs three sessions — 45 minutes of Python, 30 of Databases, 25 more of Python — saves them to study-log.json, and prints the totals.
import json DB_FILE = "study-log.json" def load_log(): try: with open(DB_FILE) as f: return json.load(f) except FileNotFoundError: return [] def save_log(entries): with open(DB_FILE, "w") as f: json.dump(entries, f, indent=2) def add_session(entries, subject, minutes): entries.append({"subject": subject, "minutes": minutes}) return entries def total_minutes(entries, subject=None): total = 0 for entry in entries: if subject is None or entry["subject"] == subject: total = total + entry["minutes"] return total log = load_log()
log = add_session(log, "Python", 45)
log = add_session(log, "Databases", 30)
log = add_session(log, "Python", 25)
save_log(log) print("Sessions saved:", len(log))
print("Python total:", total_minutes(log, "Python"), "minutes")
print("All subjects:", total_minutes(log), "minutes")Read it before you run it. The top half is the database: load, save, add, total. The bottom half uses it: load what is there, add three sessions, save, print.
Run It Twice: The Moment It Clicks
The first run prints "Sessions saved: 3", "Python total: 70 minutes", and "All subjects: 100 minutes". Those numbers are the three sessions added up: 45 plus 25 is 70 for Python, and 70 plus 30 is 100 overall.
Now run it again, without reloading the page. The second run prints "Sessions saved: 6", "Python total: 140 minutes", and "All subjects: 200 minutes". Nothing in the code changed. It loaded the file the first run saved, added the same three sessions again, and saved six entries. That is persistence: data that survives a restart.
One honest limit: in the browser editor the file lives in the page session, so closing the tab starts you over empty. On your own computer the file stays on disk. The limit is the lesson — real apps store data somewhere built to keep it, which is what a database server is for.
Four Functions, Four Jobs
load_log opens the file and turns the JSON back into a Python list. If the file is not there yet, it catches FileNotFoundError and returns an empty list — a missing database is a new one, not an error. That try and except is the difference between a program that works the first time and one that only works the second.
save_log does the opposite: it turns the list into JSON text and writes it, indented so a human can read the file. Writing the whole list every time is simple and safe at this size.
add_session appends one entry, a dictionary with a subject and minutes. total_minutes adds up the minutes, for one subject when you name one, or for all of them when you do not. The subject equals None default does real work: one function answers two questions.
What Breaks, and What It Teaches You
The first break is running the script twice and being surprised the totals doubled. Every run adds the same three sessions again — the demo has no rule for only adding what is new. A real app adds only what the user typed. The lesson: a database remembers everything you tell it, including the things you told it twice.
The second break is editing study-log.json by hand and breaking the format — a missing comma, an extra bracket — so the next load fails with a JSON error. That is why programs write files and humans mostly read them: the writer never makes a typo.
The third break is asking for a subject that is not there. total_minutes with History returns 0, not an error, because the loop finds nothing to add. Zero is right when you have logged no History — but it can also mean you typed the subject wrong. Printing the sessions tells you which.
From One File to a Real Database
A JSON file stops being enough when two people write at once, when the data grows to thousands of entries, or when you need to ask which subject you studied most last month without reading the whole file. That is when a real database earns its keep. SQLite is the next step: one file, real SQL, still no server. After that come servers like PostgreSQL, the database behind Supabase. The blog's SQL versus NoSQL guide compares the two big families.
Do not skip the file stage. Every database you will ever use is this pattern with stronger guarantees: a shape, a load, a save, and a rule for what counts as valid. Build it with a JSON file first, and you will know when you need one.
Make It Yours, Then Make It Last
Change the subjects to your own week, add a session for the subject you keep avoiding, and run it twice to watch the log grow. Then add one field to every entry — a date, or a done flag — and carry it through all four functions. One new field through four functions is the whole job of changing a database.
When the log reads the way you want, save it as a snippet called "first-database-study-log" with the note "my first database — a study log that survives a restart." Then share it with a classmate and ask them to run it twice — the second run is the demo, when the data comes back. The budget tracker is the next project to give a memory of its own.
When the Free Plan Runs Out
A log you keep all term burns executions fast — one run per session, plus test runs. Free gives you 20 executions a day, 10 AI requests a day, 10 saved snippets, 3 private snippets, and 3 collaborators per snippet. When it becomes a daily habit, that is the upgrade moment: Pro is $9/month or $69/year — unlimited saved snippets and executions, 100 AI requests a day, 10 collaborators per snippet, unlimited private snippets, and GitHub integration. Team ($19/user/month, or $15/user/month billed annually) covers a class or study group — see the pricing page.
Your next step is tonight: paste the code above into the browser editor and run it twice — watch the second run remember the first. Then save it as a snippet called "first-database-study-log" and add one real session from today.