Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💰 Expense Tracker CLI

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.


🚀 Features

  • ➕ 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 uuid module.
  • 📅 Automatic Date Stamping: Automatically logs the transaction date (YYYY-MM-DD) using Python's datetime module.
  • 📋 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.json after every modification.
  • 🛡️ Fault-Tolerant & Resilient: Handles non-numeric amounts, empty inputs, missing files, and corrupted JSON without crashing.

📁 Project Structure

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

🛠️ Requirements

  • Python 3.8+
  • No external third-party dependencies required (uses built-in standard library modules: datetime, json, uuid).

⚡ Quick Start

1. Clone the Repository

git clone https://github.com/Alt-Smash/expense-tracker.git
cd expense-tracker

2. Run the Application

python main.py

💻 Usage & CLI Overview

When 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):

1. Add an Expense

Prompts for amount (must be $> 0$), non-empty category, and non-empty description:

Choose an option (1-6): 1
Enter the amount: 15.50
Enter the category: Food
Enter a description: Coffee and pastry
Expense added successfully.

2. View Expenses

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

3. View Total Spent

Displays the aggregated sum of all logged expenses:

Choose an option (1-6): 3
Total amount spent: 60.5

4. Delete an Expense by ID

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.

5. Clear All Expenses

Clears all records in memory and resets expenses.json:

Choose an option (1-6): 5
All expenses cleared successfully.

🗄️ Data Schema (expenses.json)

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"
    }
]

🛡️ Error Handling & Reliability

  • Graceful File Recovery: If expenses.json is 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.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A Python-based command-line expense tracker with UUID-based expense management, input validation, and persistent JSON storage. Built to practice clean Python development, CRUD operations, data persistence, and Git/GitHub workflows.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages