Press enter or click to view image in full size
The Challenge
I needed to process a folder full of PDF receipts from a recent trip to Lisbon and extract key information like vendor names and amounts. Manual entry would take hours and be error-prone. Instead, I asked an LLM via CLI to build a Python script that leverages document extraction APIs to do the heavy lifting.
The Solution Architecture
The solution consists of three main components:
1. Document Extraction API: I used an existing extractor service that specializes in receipts (called “Rechnungen” — German for invoices/receipts). This API handles the complex OCR and data extraction from PDF files.
2. Python Processing Script: A simple script that orchestrates the workflow — finding files, calling the API, and aggregating results.
3. Excel Export (optional): Using Python’s openpyxl library to generate a clean summary spreadsheet.
Setting Up the Extractor
First, I needed to set up or verify the document extractor configuration. The API requires an extractor ID that’s configured to handle receipt documents:
curl -s -X GET "https://quick-extract.com/api/extractors"This returns available extractors. I’m using the existing “Rechnungen” extractor with ID YOUR_EXTRACTOR_ID.
Prompt to extract invoices
I just copied the API documentation and told Claude API to send my files to the API and extract it.
Please extract all my invoices in folder /me/Documents/ and create a table in markdown, you find the API here: https://quick-extract.com/api-docs. Use
openpyxlto then save the table as Auslagen_Lissabon_Summary.xlsx in the same folder. Create a Python Script that I can ran every time I have new invoices.
The Python Implementation by the LLM
Here’s the core of the AI solution. I added a few comments manually.
import os
import json
import requests
from openpyxl import Workbook# Configuration
EXTRACTOR_ID = "YOUR_EXTRACTOR_ID"
API_BASE_URL = "https://quick-extract.com/api"
RECEIPTS_FOLDER = "./receipts"def find_receipt_files(folder_path):
"""Find all PDF files in the specified folder"""
files = []
for filename in os.listdir(folder_path):
if filename.lower().endswith('.pdf'):
files.append(os.path.join(folder_path, filename))
return filesdef extract_receipt_data(file_path):
"""Send receipt to extraction API and get structured data"""
with open(file_path, 'rb') as f:
files = {'file': f}
response = requests.post(
f"{API_BASE_URL}/extract/{EXTRACTOR_ID}",
files=files
)
return response.json()def create_excel_summary(receipt_data, output_path):
"""Generate Excel file from extracted receipt data"""
wb = Workbook()
ws = wb.active
ws.title = "Receipts Summary"# Headers
ws.append(["Vendor", "Amount", "Currency"])# Add data: you can manage the data schema in Quick-Extract
for receipt in receipt_data:
vendor = receipt.get('vendor', 'Unknown')
amount = receipt.get('total', 0)
currency = receipt.get('currency', 'EUR')
ws.append([vendor, amount, currency])wb.save(output_path)
# Main workflow
if __name__ == "__main__":
print("Finding receipt files...")
receipt_files = find_receipt_files(RECEIPTS_FOLDER)
print(f"Found {len(receipt_files)} files to process")extracted_data = []
for i, file_path in enumerate(receipt_files, 1):
print(f"[{i}/{len(receipt_files)}] Processing: {os.path.basename(file_path)}")
data = extract_receipt_data(file_path)
extracted_data.append(data)output_path = "./Auslagen_Lissabon_Summary.xlsx"
create_excel_summary(extracted_data, output_path)
print(f"\nDone! Created Excel summary at: {output_path}")
Real Results
When I ran this on my 10 Lisbon receipts, here’s what the output looked like:
Found 10 files to process[1/10] Processing: ....pdfDone! Created Excel summary at:
/Users/me/Documents/receipts/Auslagen_Lissabon_Summary.xlsx
The generated Excel file contained a clean table:
Press enter or click to view image in full size
Key Takeaways
API-First Approach: Rather than building OCR from scratch, I leveraged an existing specialized API. This saved weeks of development time and provided better accuracy than a custom solution would.
Batch Processing: The script handles multiple files efficiently, providing progress feedback for better UX.
Structured Output: Excel format makes the data immediately useful for expense reporting and accounting workflows.
Error Handling: In production, you’d want to add retry logic, validation, and handling for edge cases (missing data, corrupted PDFs, API rate limits).
Recycling: Next time I can just use the Python Script and do not need to use the LLM to create the code again.
Potential Enhancements
Some ideas for taking this further:
- Add currency conversion for mixed-currency receipts
- Implement parallel processing for large batches
- Include receipt date extraction for time-based analysis
- Add a web interface for non-technical users
- Export to multiple formats (CSV, JSON, accounting software APIs)
- Implement receipt categorization (meals, transport, accommodation)
Conclusion
Building practical automation tools doesn’t always require complex ML models or reinventing the wheel. By combining existing APIs with simple orchestration code, I transformed a multi-hour manual task into a 30-second automated workflow. The total development time? About an hour.
The code is straightforward, maintainable, and solves a real problem. Sometimes the best solution is the simplest one that works.
Have you built similar document processing automations? What challenges did you face? Share your experiences in the comments below!