Automatically parse bank emails, track accounts, and analyze spending from a single Flask app.
[ additionally includes Gmail OAuth, PDF statement upload, budgets, and RTL/Arabic UI ]
'Ghwazi' is the Arabic-Omani word for 'Money'.
This repository contains a Flask-based personal finance app focused on parsing bank transaction emails and turning them into structured accounts, transactions, and insights. It supports both IMAP (manual email configs) and Gmail OAuth, includes PDF statement parsing, and provides dashboards, budgets, and category tools.
The primary application lives in ghwazi/ and runs via ghwazi/main.py (see Procfile).
- Email ingestion via IMAP with configurable sender/subject filters
- Gmail OAuth integration + Gmail API sync (labels, sender/subject filters)
- Transaction parsing and categorization (including counterparty matching)
- Multi-account tracking with balances and dashboards
- Budget setup and budget dashboards
- PDF statement upload and parsing
- CSV export for account transactions
- Health endpoints (
/health,/health/ready,/health/live) - RTL/Arabic UI with Flask-Babel (English also supported)
- Security basics: CSRF protection, rate limiting, secure sessions, security headers
- Flask 3.x, Flask-SQLAlchemy, Flask-Migrate, Flask-WTF
- SQLAlchemy ORM (SQLite by default; PostgreSQL in production)
- Flask-Babel (i18n + RTL)
- Gmail API + Google OAuth
- IMAP email ingestion
- PDF parsing (pymupdf, pdfplumber, pypdf)
money_tracker/
βββ ghwazi/
β βββ main.py # App entry point + CLI commands
β βββ app/
β β βββ __init__.py # App factory + middleware
β β βββ config/ # Base/dev/prod/test config
β β βββ models/ # SQLAlchemy models + repositories
β β βββ services/ # Email parsing, Gmail OAuth, budgeting
β β βββ views/ # Blueprints/routes
β β βββ templates/ # Jinja templates
β β βββ static/ # CSS/JS/images
β β βββ utils/ # Helpers, decorators, validators
β βββ translations/ # i18n catalogs (Arabic/English)
β βββ tests/
βββ scripts/ # Utility scripts
βββ requirements.txt # Production requirements (delegates)
βββ Procfile # gunicorn ghwazi.main:app
βββ runtime.txt # Python runtime for deployment
βββ transactions.db # Default SQLite database (local)
python -m venv .venv
source .venv/bin/activatepip install -r requirements.txt
# or for development tooling
pip install -r ghwazi/requirements/development.txtAt minimum, you must set a SECRET_KEY.
export SECRET_KEY="your-secret"(Optional but recommended):
export FLASK_ENV=development
export FLASK_DEBUG=1python ghwazi/main.pyApp runs at http://127.0.0.1:5000 by default.
Settings are loaded from environment variables (see ghwazi/app/config/base.py).
SECRET_KEYβ required for sessions and encryption
DATABASE_URLβ defaults tosqlite:///transactions.db
GOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRETGOOGLE_REDIRECT_URI(must match your Google OAuth app)
REDIS_URLorREDISCLOUD_URLPERMANENT_SESSION_LIFETIMESESSION_IDLE_TIMEOUT
HEALTHCHECK_TOKEN(optional; locks down/healthendpoints)
GMAIL_FIRST_SYNC_DAYSGMAIL_SYNC_STUCK_MINUTESGMAIL_SYNC_COOLDOWN_SECONDS
- Register and log in at
/auth/registerand/auth/login - Add a bank account at
/account/accounts/add - Configure email ingestion:
- IMAP: add email configs in
/email - Gmail: connect OAuth via
/oauth/google/loginand configure/oauth/gmail/settings
- IMAP: add email configs in
- Trigger email syncing from the dashboard or account pages
- Upload PDF statements via
POST /api/upload_pdf - Manage categories and budgets in
/categoryand/budget
The main app provides a simple CLI via ghwazi/main.py:
python ghwazi/main.py init-db
python ghwazi/main.py drop-db
python ghwazi/main.py test
python ghwazi/main.py lint
python ghwazi/main.py format-codepytest ghwazi/testsgunicorn ghwazi.main:appweb: gunicorn ghwazi.main:app
GET /health/β basic statusGET /health/readyβ readiness checks (DB + session manager)GET /health/liveβ liveness checks
- Default locale: Arabic (RTL)
- English support included
- Change language via
/i18n-set-lang?lang=enor/i18n-set-lang?lang=ar
- Default currency and bank presets focus on Omani banks (see
ghwazi/app/models/database.py). - SQLite is used by default for local development; PostgreSQL is recommended for production.