A lightweight, robust, and interactive command-line Expense Tracker built with Python. Effortlessly record, view, manage, and calculate your daily expenses with automatic unique IDs, timestamp tracking, and persistent JSON storage.
- ➕ Add Expenses: Record transactions with validated amount, category, and description.
- 🆔 Auto-Generated Unique IDs: Every transaction receives a unique 8-character identifier generated using Python's
uuidmodule. - 📅 Automatic Date Stamping: Automatically logs the transaction date (
YYYY-MM-DD) using Python'sdatetimemodule. - 📋 View Expenses: Formatted, numbered list displaying transaction IDs, dates, categories, amounts, and descriptions.
- 💵 Calculate Total Spent: Instantly sum up all recorded expenses.
- 🗑️ Delete by Unique ID: Remove specific expenses by providing their unique ID (case-insensitive search).
- 🧹 Clear All Records: Reset and wipe all expenses in one command.
- 💾 Persistent JSON Storage: Data is automatically loaded on launch and saved to
expenses.jsonafter every modification. - 🛡️ Fault-Tolerant & Resilient: Handles non-numeric amounts, empty inputs, missing files, and corrupted JSON without crashing.
expense-tracker/
├── .gitignore # Git ignore rules for Python & IDE files
├── expenses.json # Local JSON database for persistent storage
├── LICENSE # MIT License
├── main.py # Main application code and CLI interface
└── README.md # Project documentation
- Python 3.8+
- No external third-party dependencies required (uses built-in standard library modules:
datetime,json,uuid).
git clone https://github.com/Alt-Smash/expense-tracker.git
cd expense-trackerpython main.pyWhen you launch the app, you will see an interactive menu:
===== Expense Tracker =====
1. Add an expense
2. View expenses
3. View total
4. Delete an expense
5. Clear expenses
6. Exit
Choose an option (1-6):
Prompts for amount (must be
Choose an option (1-6): 1
Enter the amount: 15.50
Enter the category: Food
Enter a description: Coffee and pastry
Expense added successfully.
Lists all recorded expenses with formatting:
Choose an option (1-6): 2
Expenses:
1. ID: 4f8a12bc, Date: 2026-09-02, Amount: 15.5, Category: Food, Description: Coffee and pastry
2. ID: 8e3d91aa, Date: 2026-09-02, Amount: 45.0, Category: Transport, Description: Fuel
Displays the aggregated sum of all logged expenses:
Choose an option (1-6): 3
Total amount spent: 60.5
Deletes an expense matching the given ID:
Choose an option (1-6): 4
Enter the ID of the expense to delete: 4f8a12bc
Expense with ID '4f8a12bc' deleted successfully.
Clears all records in memory and resets expenses.json:
Choose an option (1-6): 5
All expenses cleared successfully.
Expenses are stored in JSON format with the following schema:
[
{
"id": "4f8a12bc",
"date": "2026-09-02",
"amount": 15.5,
"category": "Food",
"description": "Coffee and pastry"
}
]- Graceful File Recovery: If
expenses.jsonis missing or contains malformed JSON,load_expenses()safely initializes an empty list instead of crashing. - Input Validation Loops: Prevents invalid numbers, negative or zero amounts, and empty string categories/descriptions.
- Case-Insensitive ID Lookup: Expense deletion matches IDs regardless of character casing.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.