Invoice PDF Extraction to Google Sheets with Python and OCRInvoice PDF Extraction to Google Sheets with Python and OCR
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
It started with a simple request. A client told us their team was still typing invoices into a spreadsheet by hand, one by one, and asked if there was a better way. At DZ Labs we like that kind of problem: small, real, and something people deal with every single day. So I built Invoice Register. You give it a PDF invoice, and a few seconds later the data is sitting in a Google Sheet: supplier, dates, totals, and every line item in its own row. It works with digital invoices and with scanned ones too. In the video you can see the whole trip: I upload a PDF, the API answers with the structured data, the rows show up in the spreadsheet, and the service is running live in the cloud. Here is what I used to build it:
Python 3.12 and uv to manage the project and its dependencies
FastAPI and Uvicorn for the API
Pydantic to define and validate what an invoice looks like
pdfplumber to read text from digital PDFs
pdf2image, Poppler and Tesseract to read scanned invoices with OCR
LangChain and Claude to turn raw text into structured data
gspread and google-auth to write into Google Sheets
LangSmith to trace every run and see what the model did
pytest for the test suite And here is what I used to deploy it:
Docker to package the app with its system dependencies
Cloud Build and Artifact Registry to build and store the image
Google Cloud Run to run it, scaling down to zero when nobody is using it
Secret Manager to keep the API keys out of the code I will be honest: writing the code was the comfortable part. Getting it to production is where I learned the most. When the data belongs to someone else, security stops being optional. The service runs without any key files, the API is private, and every secret lives outside the code. What I enjoyed most was not the technology. It was knowing that someone will get back hours of their week. Next steps: a simple frontend for uploads, background processing, and automated deployments. If your team is still doing something by hand that a computer should be doing, I would love to hear about it.
#Python #FastAPI #LangChain #GoogleCloud #CloudRun #AI #DZLabs
Kapil's avatar
Since you're tracing runs in LangSmith, I'd separate debugging metadata from invoice contents. Can you follow a failed extraction using a document ID and error details without recording supplier or line-item data in the trace?
Jhoan Sebastian's avatar
Yes. I’d keep the trace focused on what’s needed to debug, not on the invoice itself. Each run is tagged with an internal document ID (a hash, not the file name), the pipeline stage, the model and prompt version, latency, tokens and the error type. For validation failures, I log...
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started