A beginner-friendly, modular command-line application built in Python to record daily expenses, organize spending by category, and persist records to a local JSON file.
- Add Expenses: Record new expenses with validated IDs (
EXP-001), dates (YYYY-MM-DD), categories, numeric amounts, and comma-separated tags. - View All Expenses: List all saved expense entries alongside the total spending amount.
- Category Summary: Aggregate and display total spending grouped by category.
- Search by Category: Filter and view expenses matching a specific category name.
- Persistent JSON Storage: Automatically loads existing records from
expenses.jsonat startup and saves updates on exit, safely handling missing or empty files.
spendwise_project/
│
├── expenses.json # Automatically generated JSON data store
├── models.py # Expense and ExpenseTracker data models and logic
├── storage.py # JSON serialization and file read/write handlers
├── utils.py # Regex validators and tag parsing helpers
├── main.py # Interactive CLI loop and match-case menu
└── README.md # Project documentation
- Python 3.10+ (required for
match-casestructural pattern matching) - Uses only Python standard library modules (
json,re) — no external packages required.
- Open a terminal or command prompt inside the
spendwise_projectfolder. - Run the main script:
python main.py
- Follow the on-screen menu options (
1to5) to manage your expenses.
===== SpendWise CLI =====
1. Add expense
2. View all expenses
3. View category summary
4. Search expenses by category
5. Save and exit
Enter your choice: 1
Enter expense ID (EXP-001): EXP-100
Enter date (YYYY-MM-DD): 2026-03-22
Enter category: Food
Enter amount: 250.0
Enter tags separated by commas: sandwich, burger, shawarma
Expense added successfully.
- Object-Oriented Programming (
models.py): CustomExpenseandExpenseTrackerclasses withto_dict(),@classmethod from_dict(), and__str__()methods. - Python Collections:
list— Stores sequentialExpenseobjects insideExpenseTracker.dict— Computes category-wise spending totals (get_category_totals()).set— Stores deduplicated, lowercase tags per expense (parse_tags()).
- Regular Expressions (
utils.py): ValidatesEXP-XXXIDs (^EXP-[0-9]{3}$) andYYYY-MM-DDdates (^\d{4}-\d{2}-\d{2}$). - Exception Handling (
storage.py&main.py): Safely catchesFileNotFoundError,json.JSONDecodeError, andValueErrorwithout crashing.