A simple yet powerful command-line interface (CLI) finance tracker built with Python. This application allows you to easily log your income and expenses, monitor your financial balance, and generate insightful summaries of your spending and earnings. All your financial data is persistently stored in a .csv file, ensuring your records are safe and accessible.
- Interactive Command-Line Interface: User-friendly menu-driven system for easy navigation and transaction management.
- Record Transactions: Log both income and expense transactions with details such as amount, category, and optional notes.
- Real-time Balance Tracking: Automatically calculates and updates your current financial balance with every transaction.
- Data Persistence: All your financial records are securely saved to a
finance_log.csvfile, ensuring your data is available across different sessions. - Comprehensive Financial Summaries:
- View your total income, total expenses, and overall current balance.
- Generate detailed summaries of your income and expenses, broken down by category, for better financial insight.
- Robust Input Validation: Includes validation for numerical amounts and ensures categories are properly formatted, enhancing data integrity and preventing common input errors.
- Python 3.x: This project utilizes standard Python libraries, so no external dependencies need to be installed via
pip.
-
Save the Files:
- Save the
FinanceTrackerclass code into a file namedfinance_tracker.py. - Save the CLI code (the second file you provided) into a file named
main.py.
Your project directory should look like this:
. ├── finance_tracker.py └── main.py - Save the
-
Run the Application: Navigate to the project directory in your terminal and run the
main.pyfile:python main.py
The application will launch, presenting you with the main menu. The
finance_log.csvfile will be automatically created in the same directory (or a specified folder, though the CLI uses the current directory) when you first run the application or record a transaction.
Once you run main.py, you'll see an interactive menu. Follow the prompts to add transactions, view summaries, or exit.
--- 📘 Finance Tracker Menu ---
1. Add Income
2. Deduct Expense
3. View Total Income
4. View Total Expense
5. View Current Balance Summary
6. View Summary by Category
7. Exit
Enter your choice (1-7):
- Add Income: Choose
1, enter amount, category (e.g., "Salary", "Freelance"), and notes. - Deduct Expense: Choose
2, enter amount, category (e.g., "Groceries", "Rent"), and notes. - View Summary by Category: Choose
6, then specify "Income" or "Expense" to filter, or just press Enter to see all categorized transactions.
.
├── finance_tracker.py # Core logic for managing finances and CSV operations
├── main.py # Command-line interface to interact with FinanceTracker
└── finance_log.csv # (Automatically generated) Stores all transaction data
The decimal module is used for precise financial calculations, set globally to a precision of 10 decimal places to prevent floating-point inaccuracies.
The application includes robust error handling for user inputs, catching ValueError for invalid amounts or categories. It also gracefully handles malformed rows in the CSV file by skipping them and issuing a warning, ensuring data integrity.
Contributions are always welcome! If you have suggestions for improvements, bug reports, or want to add new features, please feel free to:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name). - Make your changes.
- Commit your changes (
git commit -m 'Add new feature'). - Push to the branch (
git push origin feature/your-feature-name). - Open a Pull Request.
This project is open-source and available under the MIT License.