Skip to main content
Albero Academy

Project: Expense Tracker

A persistent expense tracker using files/JSON, data structures and functions.

Projects14 min

Step up to a small but complete application: an expense tracker that records spending, persists it to a JSON file so it survives restarts, and reports totals by category. It combines collections, files, functions and a command loop — the shape of a real tool.

What to build

  • Model each expense as a dict (amount, category, note); keep a list of them.
  • Persist the list to a JSON file on every change so data survives restarts.
  • Summarise totals per category using a dict accumulator.
  • Offer add / list / summary / quit commands.

Persistence scaffold

storage & summary
import json
from pathlib import Path
FILE = Path("expenses.json")
def load():
return json.loads(FILE.read_text()) if FILE.exists() else []
def save(expenses):
FILE.write_text(json.dumps(expenses, indent=2))
def summary(expenses):
totals = {}
for e in expenses:
totals[e["category"]] = totals.get(e["category"], 0) + e["amount"]
return totals

Stretch goals

Add date filtering (this month's spend), a budget warning per category, or export the summary to CSV (Module 6).

Key takeaways

  1. 01Combines lists, dicts, JSON persistence and functions into a real app.
  2. 02json load/dump gives durable storage with no database.
  3. 03Aggregation by category uses a dict accumulator (get with default 0).
  4. 04A command loop (add/list/summary/quit) makes it interactive.
  5. 05Stretch it with date filters, budgets, or CSV export.

Finished this chapter?

Mark it complete to track your progress through Python.