Automatically organize invoices and receipts: read files, extract key information, standardize naming, and categorize and archive.
Use Cases
- The user says "Help me organize my invoices" or "Categorize the invoices in the Downloads folder"
- Need to organize a full year's invoices before filing taxes
- Daily receipt management, archived by month/category
Dependency Installation
Automatically installed on first use:
pip install pypdf Pillow
Execution Method
Use a Python script to scan folders, identify invoice files, extract information, and archive them.
1. Scan the target folder
import os
from pathlib import Path
def scan_invoices(folder: str) -> list:
"""Scan folder for invoice files (PDF/image)."""
extensions = {'.pdf', '.png', '.jpg', '.jpeg'}
invoices = []
for f in Path(folder).rglob('*'):
if f.suffix.lower() in extensions:
invoices.append(f)
return invoices
2. Extract invoice information
For PDF invoices:
from pypdf import PdfReader
def extract_pdf_text(path: str) -> str:
"""Extract text from PDF invoice."""
reader = PdfReader(path)
text = ""
for page in reader.pages:
text += page.extract_text() or ""
return text
For image invoices, use LLM visual capabilities to recognize the content.
3. Structure the information
Identify from the extracted text:
- Date: invoice issue date
- Amount: total amount
- Merchant/Supplier: name of the issuing party
- Type: dining/transportation/office supplies/accommodation, etc.
- Invoice Number: if available
4. Standardize naming and archive
# 命名规则:日期_商家_金额_类型.ext
# 示例:20250115_星巴克_35.00_餐饮.pdf
# 目录结构
# 发票整理/
# ├── 2025-01/
# │ ├── 餐饮/
# │ ├── 交通/
# │ └── 办公用品/
# └── 2025-02/
Output Specifications
- Before operating, first list the discovered invoices and ask the user for confirmation
- After organizing is complete, output a summary table (quantity, total amount, category statistics)
- Keep the original files without deleting them; only copy them into the new directory structure
- Place unrecognizable invoices separately into a "To Be Categorized" folder