How mulinco/extrator-pdf-streamlit works
Project type and purpose
• This is a monolithic, Python‐based Streamlit application whose goal is to let end users upload PDF “Declarações de Importação,” extract structured fields (D.I., Invoice, PO, HAWB, etc.) via regex and PyMuPDF, display results in the browser, and export a consolidated Excel report using Pandas and XlsxWriter.
File structure
• Top‐level files:
• app.py – the Streamlit entrypoint
• anonimizar_pdfs.py – a standalone PDF‐anonymization utility (auxiliary script)
• requirements.txt – dependencies (Streamlit, PyMuPDF, Pandas, XlsxWriter…)
• pages/ directory: multipage Streamlit modules (e.g. 2_Fechamento_Aeronave.py)
• pdfs_para_github/: sample PDFs for testing/demonstration
• .devcontainer/: dev environment configuration
README for insights
• The README describes a two‐tier flow:
• Frontend: browser ↔ Streamlit UI (upload button, table view, download button)
• Backend: app.py → PyMuPDF for page iteration → regex extraction → Pandas DataFrame → XlsxWriter to .xlsx
1. User’s Web Browser (Client)
2. Streamlit Server (app.py + pages/)
3. PDF Processing Module (PyMuPDF wrapper)
4. Data Extraction Module (Regex functions)
5. Data Layer (Pandas DataFrame)
6. Export Module (XlsxWriter)
7. Optional Utility Script (anonimizar_pdfs.py)
• Browser → (HTTP/WebSocket) → Streamlit Server (file upload trigger)
• Server → PDF Processing → loops per page → raw text
• Raw text → Data Extraction → structured records
• Structured records → Pandas DataFrame → in‐memory table
• DataFrame → Export Module → .xlsx file
• Export Module → Browser download response
• Auxiliary: anonimizar_pdfs.py reads/writes PDFs on disk
c. Architectural patterns & principles:
– MVC‐style separation:
• View = Streamlit UI components
• Controller = app.py’s control flow & page scripts
• Model = DataFrame + extraction functions
– Single process, event‐driven (Streamlit’s re‐run on interaction)
– Modular code: PDF I/O, regex extraction, data transformation, export
d. Key frameworks & libraries:
– Streamlit for UI & app server
– PyMuPDF (fitz) for PDF reading
– Python’s re module for regex matching
– Pandas for data management
– XlsxWriter as Excel engine