Free

Expense Manager (Python CLI)

The totals belong in the database, not in a Python loop — and the project times both to prove it.

  • Python
  • SQLite
  • SQL

About this project

A command-line expense manager backed by SQLite, which ships with Python — nothing to install and no server to run. Add an expense, list and filter by month or category, and see totals per category and per month.

The idea it is built around is that the aggregation belongs in the database. Most beginner versions of this project select every row and add them up in a Python loop. That is fine on fifty rows and wrong in shape, and the project settles it by measurement rather than assertion: `python expenses.py bench` builds a throwaway database, prints the query plans, and times the loop against GROUP BY at four table sizes. The gap widens as the table grows, which is the actual argument.

The second theme is money. Amounts are stored as whole paise, never as a float, and `python expenses.py floats` demonstrates why with live arithmetic — including the fact that reading a typed "8.70" through float() gives you 869 paise rather than 870, so the money is gone before the database has even been opened.

What you will learn

  • Let the database aggregate with GROUP BY instead of pulling every row into Python
  • Read an EXPLAIN QUERY PLAN and see what an index changes
  • Store money as whole paise, and see what a float column does to a running total
  • Build a real command-line interface with argparse and subcommands
  • Validate dates and amounts before they reach the database, with errors a person can act on

Before you start

  • Python basics — functions, lists and dictionaries
  • Python 3.10 or newer. SQLite comes with Python, so there is nothing to install.

New to Python? The free Python course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.