A full-stack web application to analyze and categorize monthly expenses from bank statements (CSV & PDF) with intelligent auto-categorization.
Managing personal finances is challenging when bank statements are just raw transaction data. This app transforms messy CSV exports and PDF bank statements into actionable insights by:
- Automatically categorizing transactions using pattern matching (170+ merchant rules)
- Extracting transactions from PDF bank statements (ICICI, HDFC, SBI, etc.)
- Learning user preferences over time
- Providing clear salary vs. spending analysis
| Feature | Description |
|---|---|
| π€ CSV Upload | Upload any bank statement CSV |
| π PDF Upload | Extract transactions from PDF bank statements |
| π€ Auto-Categorization | Rule-based engine with 170+ merchant rules |
| π§ Learning System | Remembers user categorizations for future transactions |
| π Dashboard | Visual summary of income, expenses, and balance |
| βοΈ Inline Editing | Change categories with instant save |
| π΅ Credit Tracking | Track money received from others |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND β
β HTML5 β’ CSS3 β’ Responsive Design β’ Dynamic Templates β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β BACKEND β
β Python 3 β’ Flask β’ Pandas β’ RESTful Routes β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β DATA LAYER β
β CSV Parsing β’ PDF Extraction β’ Regex Matching β’ JSON β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Python 3.8+ - Core programming language
- Flask - Lightweight WSGI web framework
- Pandas - Data manipulation and analysis
- pdfplumber - PDF text extraction
- camelot-py - PDF table extraction (stream mode)
- Gunicorn - Production WSGI HTTP server
- HTML5/CSS3 - Responsive UI with modern gradients
expense-tracker/
βββ webapp.py # Main Flask application (1400+ lines)
β βββ Routes # 8 API endpoints
β βββ Data Processing # CSV parsing, PDF extraction, categorization
β βββ Template Rendering # Dynamic HTML generation
βββ create_sample_pdf.py # Generate sample PDF for testing
βββ test_pdf_processing.py # PDF extraction tests
βββ sample_statement.csv # Sample CSV bank statement
βββ user_mappings.json # Persistent learned mappings (JSON)
βββ uploads/ # Temporary file storage (git-ignored)
βββ requirements.txt # Python dependencies
βββ Procfile # Production deployment config
βββ README.md
1. Auto-Categorization Engine
GLOBAL_RULES = {
'SWIGGY': 'Food', 'ZOMATO': 'Food', 'HUNGERBOX': 'Food',
'AMAZON': 'Shopping', 'FLIPKART': 'Shopping', 'MYNTRA': 'Shopping',
'UBER': 'Transport', 'OLA': 'Transport', 'RAPIDO': 'Transport',
'ZERODHA': 'Investments', 'GROWW': 'Investments',
'BOOKMYSHOW': 'Entertainment', 'NETFLIX': 'Entertainment',
'BIGBASKET': 'Groceries', 'BLINKIT': 'Groceries',
# 170+ merchant rules across 12 categories
}2. PDF Extraction Pipeline
- Camelot (stream mode) - Extracts tabular data from PDF bank statements
- pdfplumber (fallback) - Text-based extraction when table detection fails
- Handles multi-row headers, merged columns, and multi-line transactions
- Supports date formats:
DD/MM/YYYY,DD-MM-YYYY,DD.MM.YYYY - Deduplication to handle overlapping page extractions
3. Learning System
- Stores user corrections in JSON
- Prioritizes learned mappings over global rules
- Persists across sessions
4. Smart Detection
- Auto-detects salary (credits > βΉ50,000)
- Identifies auto/transport transactions by amount patterns
- Calculates overspending and net balance
# Clone the repository
git clone https://github.com/harininaik/expense-tracker.git
cd expense-tracker
# Install dependencies
pip install -r requirements.txt
# Run the application
python webapp.py
# Open in browser
# http://127.0.0.1:5000| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Dashboard with expense summary |
GET |
/transactions |
All transactions with inline editing |
GET |
/mappings |
View/edit saved category mappings |
GET |
/upload |
Upload page for new CSV/PDF |
POST |
/upload |
Process uploaded CSV or PDF file |
POST |
/categorize |
Batch save new categorizations |
POST |
/update_mapping |
Update single mapping |
GET |
/delete_mapping/<name> |
Remove a mapping |
Upload your bank statement PDF directly β the app extracts transactions automatically.
Supported banks: ICICI, HDFC, SBI, Axis, Kotak, and most Indian banks with tabular PDF statements.
How it works:
- Camelot (stream mode) detects table structure in the PDF
- Multi-row headers are scanned and mapped to standard columns
- Multi-line transactions are merged (UPI/NEFT/IMPS descriptions)
- Duplicate rows from overlapping pages are removed
- Falls back to pdfplumber if Camelot finds no tables
Your bank statement CSV must have these columns in this order:
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | Column 6 | Column 7 |
|---|---|---|---|---|---|---|
| Date | Date | Description | - | Debit | Credit | Balance |
Date,Date,Description,-,Debit,Credit,Balance
28/01/2026,28/01/2026,UPI/CR/123456789/SALARY/COMPANY NAME/REF123,-,-,93260.00,93260.00
28/01/2026,28/01/2026,UPI/DR/987654321/SWIGGY/SWIGGY/Payment for order,-,450.00,-,92810.00
29/01/2026,29/01/2026,UPI/DR/456789123/AMAZON/Amazon Pay/Shopping,-,1299.00,-,91511.00
29/01/2026,29/01/2026,UPI/DR/789123456/RAPIDO/Rapido/Ride payment,-,85.00,-,91426.00
30/01/2026,30/01/2026,UPI/CR/321654987/FRIEND NAME/Payment received,-,-,500.00,91926.00
30/01/2026,30/01/2026,UPI/DR/654987321/ZEPTO/Zepto/Groceries,-,320.00,-,91606.00PhonePe:
- Open PhonePe β Profile β Transaction History
- Click "Download Statement" β Select date range
- Download as CSV
Google Pay:
- Open Google Pay β Tap profile picture
- Go to "Transaction history" β Export
- Download CSV file
Bank Apps (HDFC, ICICI, SBI, etc.):
- Login to net banking
- Go to Accounts β Statement
- Select date range β Download as CSV
- Date format:
DD/MM/YYYY(e.g., 28/01/2026) - Debit = Money spent (outgoing)
- Credit = Money received (incoming)
- Use
-for empty debit/credit fields - Description should contain merchant/person name
π See
sample_statement.csvfor a complete working example!
Compatible with: PhonePe, Google Pay, Paytm, HDFC, ICICI, SBI, Axis Bank, Kotak
- Summary Cards - Salary, Spent, Overspent, From Others, Balance
- Category Breakdown - Visual spending by category with percentages
- Credits Section - Money received from others
- Quick Categorize - Dropdowns for uncategorized transactions
Rent Food Groceries Shopping Transport Entertainment Investments Family Friends Maid/Cook Travel Others
# webapp.py - GLOBAL_RULES dictionary
GLOBAL_RULES = {
'NEW_MERCHANT': 'Category',
}# webapp.py - CATEGORIES list
CATEGORIES = [
"Rent", "Food", "NewCategory",
]# webapp.py - Line 195
salary = df[df['Credit'] > 50000]['Credit'].sum() # Change 50000- π Monthly comparison charts (Chart.js)
- π Budget alerts and spending limits
- π± Progressive Web App (PWA)
- π User authentication (Flask-Login)
- π€ Export to PDF/Excel
- π¦ Direct bank API integration
- π¦ Support more bank PDF formats
Contributions are welcome! Here's how:
- Fork the repository
- Create feature branch (
git checkout -b feature/NewFeature) - Commit changes (
git commit -m 'Add NewFeature') - Push to branch (
git push origin feature/NewFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Harini Naik
Built with Python & Flask
Made with β€οΈ for better personal finance management
β Star this repo if you found it helpful!