Hook
More breakout videos from this creator.
Here is how to build a PDF Invoice to Excel automation in Python with around 80 lines of code using the Gemini API for free. In this video you will learn how to extract structured data from PDF invoices using a JSON schema, loop through a whole folder of files with glob, and append every result into one growing Excel spreadsheet using pandas. Let me know if you want the source code. I could share import os from google import genai from google.genai import types import pathlib import json import pandas as pd # pip install openpyxl google-genai pandas client = genai.Client(api_key="AQ.Ab8RN6J29225Q1zZ7wLP0CusvdCnttO") invoice_folder = pathlib.Path("invoices") excel_file = "invoices_db.xlsx" schema = { "type": "OBJECT", "properties": { "invoice_number": {"type": "STRING"}, "date": {"type": "STRING"}, "total_amount": {"type": "NUMBER"}, "items": { "type": "ARRAY", "items": { "type": "OBJECT", "properties": { "description": {"type": "STRING"}, "price": {"type": "NUMBER"} } } } }, "required": ["invoice_number", "date", "total_amount", "items"] } all_rows = [] for pdf_file in invoice_folder.glob("*.pdf"): print(f"Processing {pdf_file.name}...") response = client.models.generate_content( model="gemini-3.5-flash", contents=[ types.Part.from_bytes( data=pdf_file.read_bytes(), mime_type="application/pdf" ), "Extract the data from this invoice.", ], config={ "response_mime_type": "application/json", "response_schema": schema, }, ) try: data = json.loads(response.text) items_text = "".join([f"{item.get('description')}:{item.get('price')}" for item in data.get('items')]) data["items"] = items_text all_rows.append(data) print(f"Extracted Invoice #{data.get('invoice_number')}") except json.JSONDecodeError: print(f"Could not parse {pdf_file.name}") if all_rows: new_df = pd.DataFrame(all_rows) if os.path.exists(excel_file): existing_df = pd.read_excel(excel_file) updated_df = pd.concat([existing_df, new_df], ignore_index=True) else: updated_df = new_df updated_df.to_excel(excel_file, index=False) print(f"Saved {len(all_rows)} to {excel_file}") else: print("No rows to save.")