Practical ways to automate invoice and email triage, reports, spreadsheet clean-up and document extraction with Python, while keeping people in control of important decisions.
In many Indian SMEs, a surprising amount of skilled time goes into copying data between emails, PDFs and spreadsheets. An accounts executive downloads vendor invoices and types them into Tally or an ERP. A sales coordinator merges three Excel exports every Monday to produce a report. A support team reads every incoming email just to decide who should handle it.
These tasks are repetitive and rule-heavy, which makes them good candidates for automation. Python, with its data libraries and growing set of AI tools, is often the most practical way to do it. The aim is not to remove people, but to let them spend their time checking and deciding rather than copying and pasting.
Pick the right workflows first
Before writing any code, list candidate tasks and score them on a few simple questions:
- Does it happen often (daily or weekly) and take noticeable time?
- Are the inputs digital already (emails, PDFs, Excel or CSV exports, an API)?
- Can you write down the rules a person follows, even roughly?
- What is the cost of a mistake, and how would you catch one?
Good starting points include invoice intake, email triage, weekly MIS reports, spreadsheet clean-up and extracting fields from standard documents such as purchase orders or delivery challans.
Spreadsheet clean-up and report generation
This is usually the quickest win and needs no AI at all. pandas reads Excel and CSV files, cleans them and writes the result back to Excel through openpyxl. The example below combines monthly sales exports, standardises messy columns, removes duplicates and writes a summary workbook with two sheets.
from pathlib import Path
import pandas as pd
frames = [pd.read_excel(f) for f in Path("exports").glob("sales_*.xlsx")]
df = pd.concat(frames, ignore_index=True)
df.columns = df.columns.str.strip().str.lower().str.replace(" ", "_")
df["customer"] = df["customer"].str.strip().str.title()
df["gstin"] = df["gstin"].astype(str).str.upper().str.strip()
df["invoice_date"] = pd.to_datetime(df["invoice_date"], dayfirst=True, errors="coerce")
df["amount"] = pd.to_numeric(df["amount"], errors="coerce")
bad = df[df["invoice_date"].isna() | df["amount"].isna()]
df = df.dropna(subset=["invoice_date", "amount"]).drop_duplicates(subset=["invoice_no"])
summary = (df.groupby([df["invoice_date"].dt.to_period("M").astype(str), "customer"])
["amount"].sum().reset_index(name="total_amount"))
with pd.ExcelWriter("sales_summary.xlsx", engine="openpyxl") as xl:
summary.to_excel(xl, sheet_name="Summary", index=False)
bad.to_excel(xl, sheet_name="Needs review", index=False)
Note the "Needs review" sheet. Rather than silently dropping rows with unreadable dates or amounts, the script puts them in front of a person. The dayfirst=True option matters for Indian date formats such as 05/04/2026, which would otherwise be read as 4 May in some cases.
Email and invoice triage
Routing incoming messages is a classification problem. You can approach it at three levels of sophistication:
- Rules: sender domain, keywords in the subject, attachment type. Simple and transparent, and often enough to sort a large share of routine messages; measure this on your own data.
- A small trained classifier: if you have a few hundred labelled past emails, a scikit-learn pipeline with
TfidfVectorizerandLogisticRegressioncan learn categories such as "invoice", "payment query", "complaint" and "order". - A language model: useful when categories are subtle or emails mix Hindi and English. Send the message text, ask for one category from a fixed list, and validate that the answer is actually on that list.
Whichever you choose, include a confidence threshold. Low-confidence items should go to a general queue for a person to sort, not be forced into a category.
Document extraction
Extracting fields from invoices, purchase orders and forms is where AI adds the most value over plain scripting. A typical pipeline looks like this:
- Get the text: digital PDFs can be read with libraries such as pdfplumber; scanned documents need OCR first (Tesseract via pytesseract is a common open-source choice).
- Extract fields: regular expressions work well for fixed patterns such as GSTIN, PAN or invoice numbers. For layouts that vary from vendor to vendor, a language model or a document AI service can return structured fields in JSON.
- Validate: check the GSTIN format, confirm that line items add up to the total, verify tax amounts against rates, and match the vendor against your master data.
- Store: push validated records into your ERP or accounting system through its API or an import file.
Validation is what separates a reliable automation from a demo. Every extracted field that can be cross-checked should be.
Human-in-the-loop approval
For anything involving payments, credit notes or customer commitments, the automation should prepare the work and a person should approve it. A simple design: the script writes proposed records with a status of "pending", a small web page or spreadsheet shows them alongside the source document, and only approved records are posted. Record who approved what and when.
This approach also gives you feedback. Each correction a reviewer makes is a labelled example you can use to improve rules or retrain a classifier.
Scheduling, logging and data protection
An automation that runs only when someone remembers to start it is not really automated. Options include cron on a Linux server, Windows Task Scheduler, or a workflow tool such as Apache Airflow once you have many interdependent jobs. Whatever you use:
- Use Python's
loggingmodule to record each run: start time, files processed, records created, records sent for review and errors. - Send an alert (email or chat message) when a job fails or when the review queue grows unusually large.
- Make jobs safe to re-run, for example by tracking processed file names or invoice numbers so that nothing is posted twice.
- Keep credentials in environment variables or a secrets store, not in the script.
- If you send documents to an external AI service, check what personal data they contain and how the provider handles it, in line with the DPDP Act 2023.
How NextWebGen can help
NextWebGen builds business software, including ERP systems and the integrations around them, and can help you identify which workflows to automate and connect Python scripts, AI services and approval screens to your existing systems. If manual data entry is slowing your team down, look at our ERP services and get in touch.



