All projects

completedPython / JSON

Expense Tracker

A command-line expense and wallet tracker in Python with category, date, and amount filtering and local JSON persistence.

  • Python
  • JSON
~/expense_tracker
$ python3 expense_traker.py
Do you want upload your last data changes? (y/n): n
==Current wallet balance:  0 $ ==
WARNING: Your wallet balance is low! Income is required.
# … menu omitted
chose one of the previous options: 4
(Enter 0 to exit)
How much do you want to add to wallet? 500
Enter a description for it: part-time job
Amount of 500 $ was added to the history successufully!
(Enter 0 to exit)
How much do you want to add to wallet? 0
==Current wallet balance:  500 $ ==
# … menu omitted
chose one of the previous options: 1
(Enter 0 to exit)
How much is the expense? 120
what category is the expense? groceries
Add a description for the expense: weekly shopping
Expense number: 1 was added to the history successufully!
(Enter 0 to exit)
How much is the expense? 0
==Current wallet balance:  380 $ ==
Excerpt from a real session of the public repo: the menu printed between steps, blank lines, and the final exit are left out.

Overview

A menu-driven command-line application for tracking personal expenses and income, and computing the resulting wallet balance from both histories. It supports filtering expense and income records by date, category, and amount, and persists all data to a local JSON file so history survives between runs.

Architecture

The application is organized around an object-oriented model of expenses, income, and the wallet, with expense and income histories tracked separately and the wallet balance derived from both rather than stored as an independent value. All state loads from and saves to a single local JSON file.

Key Features

  • Add and remove individual expense and income entries
  • View full expense and income history
  • Filter expenses by amount, category, or date, and income by amount or date
  • Automatic wallet balance calculation from combined expense and income history
  • Input validation on entered amounts, categories, and dates
  • Persistent local storage via a JSON save file

Technical Challenges

  • Keeping the wallet balance correct and consistently derived from two separately tracked histories instead of letting it drift out of sync
  • Designing multi-criteria filtering by date, category, and amount over a plain list of records without a database query layer

Engineering Decisions

  • Kept expenses and income as two distinct histories rather than one combined ledger, since they're filtered and displayed differently, and derived the balance from both instead of storing it separately
  • Chose JSON file storage over a database for a project at this scale, while recognizing in hindsight that splitting the single-file script into separate modules and moving to SQLite would be the right next step for maintainability

Technologies Used

Python, using the standard library's json module for persistence and datetime for date handling and filtering, with no external dependencies.

Lessons Learned

  • Practiced core object-oriented programming and organizing a larger Python program than a single script
  • Learned practical JSON read/write persistence and date/time handling
  • Recognized in retrospect that a single-file structure limits maintainability, which now informs how later projects are split into modules from the start