A tiny, pure-Python desktop tool that lets you drag a rectangle on your screen (like Snipping Tool), runs OCR on the selection, extracts all numbers, treats values in parentheses as negative (accounting style), and pops up a clean result window with the total and the list of parsed numbers.
Why? Manually adding amounts from tables, invoices, dashboards, or web apps is slow and error-prone. SnipSum makes it one drag-and-copy.
- Demo
- Features
- Tech Stack
- Folder Structure
- Quick Start
- Usage
- How It Works
- Configuration & Customization
- Troubleshooting
- Tests
- Packaging (Optional)
- Roadmap
- Security & Privacy
- Contributing
- License
- Credits
- Why I built this
- 🖼️ Snip like a pro: full-screen overlay; drag to select any region.
- 🔎 OCR on device: uses Tesseract OCR via
pytesseract(no internet required). - ➕ Smart parsing: handles
1,234.56,1.234,56,$120.00,(45.67), and120-(trailing minus). - 🧮 Accounting aware: parentheses → negative values.
- 📋 Copy friendly: copy the total; inspect parsed numbers + their raw tokens.
- 🔐 Private by design: processing is 100% local.
- 🪟 Beginner-friendly code: small, modular files you can read in one sitting.
- GUI: Tkinter (Python standard library)
- Screen capture:
mss - Images: Pillow (PIL)
- OCR: Tesseract via
pytesseract
(Optional swap: EasyOCR for a pure-pip OCR with no system EXE)
snipsum_py/
├─ app.py # Entry point & glue
├─ ui.py # Overlay snipper + results window (Tkinter + MSS + PIL)
├─ ocr.py # OCR helpers (Tesseract; lightweight preprocessing)
├─ parse.py # Number extraction & summing (Decimal-based)
├─ requirements.txt
└─ tests/
└─ test_parse.py # A few sanity tests for the parser
pip install -r requirements.txtrequirements.txt:
mss
pillow
pytesseract
-
Windows:
- Install the 64-bit build (commonly “UB Mannheim” build).
- Default path:
C:\Program Files\Tesseract-OCR\tesseract.exe - You can skip editing PATH; SnipSum tries common paths and also allows hard-coding.
-
macOS (Homebrew):
brew install tesseract
-
Ubuntu/Debian:
sudo apt-get update sudo apt-get install tesseract-ocr
Verify (optional):
tesseract -vor in Python:
import pytesseract; print(pytesseract.get_tesseract_version())
python app.py- Your screen will dim; drag to select a region.
- Release the mouse → a small window appears with the total and parsed numbers.
- Buttons: Copy Total, Save Snapshot, Re-Snip.
- Cancel snip: Press
Escwhile the overlay is active. - Re-Snip: Use the “Re-Snip” button on the result window.
- Save snapshot: Saves your cropped selection as a PNG file.
-
Overlay & Capture (
ui.py)
Full-screen Tkinter window shows a screenshot viamss. Drag a rectangle → crop to a PIL image. -
OCR (
ocr.py)
Light preprocessing (grayscale + autocontrast).pytesseractruns with a character whitelist optimized for numeric/currency characters. -
Parsing & Sum (
parse.py)- Regex finds numeric tokens (supports thousands/decimal separators, currencies, parentheses, trailing minus).
- Detects decimal separator via the rightmost-separator heuristic (EU formats handled).
- Converts using
decimal.Decimal(avoids float rounding errors). - Returns a total and the list of
(Decimal value, raw_token).
-
Tesseract path (Windows):
Auto-detection tries common install paths. If needed, set explicitly inocr.py:import pytesseract pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
-
Character whitelist: tweak for your data:
# ocr.py WHITELIST = "0123456789.,-()$€£₹% RsPKR"
-
Ignore percentages:
The parser skips tokens ending with%. To include them, adjust thePCTregex logic inparse.py. -
Parentheses as negative:
Implemented in_to_decimal()inparse.py. Change the rule if your workflow differs.
- Ensure Tesseract is installed (see above).
- On Windows, verify the path:
"C:\Program Files\Tesseract-OCR\tesseract.exe" -v - Set
pytesseract.pytesseract.tesseract_cmdto that path inocr.py.
- Zoom your source (e.g., browser zoom 125–150%) before snipping.
- Increase font size if possible.
- Keep the selection tight around the numbers to reduce noise.
- The parser infers decimal separator from tokens. If sources are mixed (
,and.used inconsistently), normalize the source or adjust_decide_decimal_sep().
msscaptures the virtual screen (all monitors). If coordinates seem off with unusual DPI scaling, try 100–150% OS scaling.
pip install pytest
pytest -qtests/test_parse.py includes:
- Parentheses → negative
- EU decimal comma support
- Date-like strings ignored
Add more tests as you encounter new formats.
Create a standalone Windows EXE:
pip install pyinstaller
pyinstaller --noconsole --onefile --name SnipSum app.pyNote: Tesseract remains an external dependency; your EXE still requires Tesseract installed on the target machine.
-
v1.1 (Python-only)
- Global hotkey to launch/re-launch snipper.
- Include/exclude checkboxes for individual values.
- CSV export (numbers + raw token).
- Session history with thumbnails.
- Optional EasyOCR backend (pure-pip; no system Tesseract).
-
v2 (ideas)
- Column-mode (sum a visually aligned column).
- Currency-only filter & per-currency totals.
- Regex presets (include/exclude patterns).
- PDF/image file import (no snip required).
- All processing happens locally on your machine.
- No data is sent anywhere by default.
- A snapshot is saved only if you click Save Snapshot.
Pull requests welcome! Good first issues:
- Add a global hotkey launcher.
- Add a “Copy CSV” button with value + raw token.
- Toggle “ignore percentages” in the UI.
- Improve EU format detection heuristics.
- Add column-mode.
This project is licensed under the MIT License.
Create a LICENSE file with:
MIT License
Copyright (c) 2025 Muhammad Ibrahim
Permission is hereby granted, free of charge, to any person obtaining a copy...
- Tesseract OCR
- pytesseract
- Pillow
- python-mss
- Tkinter (Python standard library)
At a previous job, I had to total many order amounts by hand from screenshots and web pages. It was slow and error-prone. SnipSum scratches that itch: select an area on screen, and it instantly totals all the amounts—treating accounting parentheses as negatives. It’s a beginner-friendly, pure-Python desktop app you can clone, read, and improve in an afternoon.
