Automated PDF Invoice Sorter – Folder Vendor
Clear professional description of the code solution
Task: Create a complete, production‑ready Python automation script that scans a directory of PDF invoices, extracts key information, and sorts each invoice into a vendor‑specific folder. The solution must be robust, well‑documented, and ready to run on a typical Windows/macOS/Linux environment.
Exact Requirements:
-
Core Functionality
- Recursively scan a user‑specified input folder for PDF files.
- For each PDF, extract the following fields:
- Vendor/Company Name
- Invoice Number
- Invoice Date (ISO YYYY‑MM‑DD)
- Total Amount (numeric, with currency symbol if present)
- If the PDF is image‑based, fall back to OCR using
pytesseract(assume Tesseract is installed). - Use
pdfplumber(orPyPDF2if you prefer) for text extraction; prefer the method that yields the highest confidence.
-
Sorting Logic
- Create an output folder structure:
//. - Rename each invoice file to the format
YYYYMMDD_InvoiceNumber_VendorName.pdf. - Move the renamed file into the corresponding vendor folder.
- Create an output folder structure:
-
Logging & Reporting
- Generate a detailed log file (
invoice_sorter.log) with timestamps, processed file names, extracted fields, and any errors or warnings. - Produce a CSV summary (
invoice_summary.csv) containing one row per processed invoice with columns:OriginalFilePath, NewFilePath, Vendor, InvoiceNumber, InvoiceDate, TotalAmount, ExtractionMethod, Status.
- Generate a detailed log file (
-
Configuration
- Accept all parameters via a single YAML configuration file (
config.yaml) with sections for:input_folderoutput_folderlog_level(e.g., INFO, DEBUG)ocr_language(default “eng”)field_patterns(regular expressions for vendor, invoice number, date, amount)
- Provide a command‑line interface (
python invoice_sorter.py --config config.yaml) that validates the config and prints a helpful usage message if required fields are missing.
- Accept all parameters via a single YAML configuration file (
-
Error Handling
- Gracefully handle corrupted PDFs, missing fields, or OCR failures.
- For any invoice where required fields cannot be extracted, move the file to an
unprocessedsubfolder and log the reason.
-
Code Quality
- Use type hints throughout.
- Include a module‑level docstring describing purpose, usage, and dependencies.
- Follow PEP 8 style; include
# noqa: E501where necessary. - Implement logging with the standard
logginglibrary, respecting thelog_levelfrom the config.
-
Packaging
- Provide a
requirements.txtlisting exact versions of all third‑party libraries. - Include a concise
README.mdwith:- Installation steps (virtual environment creation,
pip install -r requirements.txt). - Tesseract installation guidance for each OS.
- Example
config.yaml. - How to run the script and interpret the output.
- Installation steps (virtual environment creation,
- Provide a
Expected Output Format:
When you respond, deliver the following files in plain text, each clearly labeled with a markdown code fence and the appropriate filename extension:
invoice_sorter.py– the full Python script.config.yaml– a sample configuration file with placeholder values and comments.requirements.txt– list of dependencies.README.md– installation and usage guide.
Each file should be presented as:
# invoice_sorter.py
# config.yaml
# requirements.txt
# README.md
Make sure the script runs without modification after installing the listed requirements and setting up Tesseract. Do not include any explanatory text outside of the file sections.
Related Prompts
More prompts in Coding & Development
This Prompt Ads Sequential Function Calling To Models Other Than GPT 0613
This prompt ads sequential function calling to models other than GPT-0613
Create a personalized workout routine
Tailor a workout routine specifically designed for individual fitness goals
GODMODE CHEATCODE
God Writes You a Letter Today. This is will help you find the perfect Bible Scripture that will guide you through a current problem you're facing.
Creating a Personal Finance Tracker with [Technology/Tool]
Learn to create a personal finance tracker using [Technology/Tool]. Get code samples and budgeting tips.
Build an entire application using bubble.io with ChatGPT4
Build an entire app with bubble.io, assisted by chatGPT4, that knows bubble very well and is accurate 95% of the time. This prompt will help you maximize the quality of chatGPT assistance. Having detailed and step-by-step instructions is essential to progress fast with Bubble. This initial prompt will help you get started on a good basis. Follow it because I will make it even better.
Become LawyerGPT
Are you in a legal bind? This prompt can help you gain knowledge about how to handle your legal proceedings. DISCLAIMER: Please meet with a real lawyer to discuss your options.