Skip to content
All projects Case study · automation

Invoice Organizer

A Python program that reads Brazilian electronic invoices (NF-e), sorts the files by supplier and builds an Excel report ready for the accountant. A task I used to do by hand, now done with a single command.

Role
Code and documentation
Technologies
Python · XML · openpyxl
Type
Study project · 2026
Code
On GitHub ↗
Overview

A problem I knew first-hand

Before moving into tech, I worked for four years as an accounting assistant. One of the most repetitive tasks was organizing invoices: files named download.xml or final invoice (2).xml that could only be identified by opening them one by one.

When I started learning Python, I wanted my first project to solve a real problem, and this one I knew well. The Organizer reads what is inside each invoice instead of trusting the file name, and does in under a second what used to take minutes.

The goal

What the program had to do

  • Read the data inside each invoice
  • Sort by supplier, with clear file names
  • Build a report ready for the accountant
  • Keep going when a file is broken

All without touching the original files: the program always works on copies.

Features

From a messy folder to a report

notas/
├── download.xml
├── NF digitalizada (1).xml
├── nota fiscal novembro.xml
├── nota_cafe.xml
├── nota_estragada.xml
└── …
Before: names that say nothing (or mislead)
notas_organizadas/
├── relatorio.xlsx
├── Café Serra Verde Comércio ME/
│   ├── 2026-10-08_…_NF1008.xml
│   └── 2026-11-10_…_NF1043.xml
├── Gráfica Pão de Queijo Ltda/
│   ├── 2026-10-29_…_NF1032.xml
│   └── 2026-11-27_…_NF1067.xml
└── …
After: one folder per supplier
> python organizador.py
✅ download.xml → Tech Minas Informática Ltda
✅ NF digitalizada (1).xml → Café Serra Verde Comércio ME
✅ nota fiscal novembro.xml → Gráfica Pão de Queijo Ltda
✅ nota_cafe.xml → Tech Minas Informática Ltda
…
⚠️ Arquivo com problema, pulei: nota_estragada.xml

Pronto! 10 notas organizadas.
Relatório salvo em: notas_organizadas\relatorio.xlsx

XML parsing

Extracts issuer, number, date and amount from each NF-e, following the document's official structure.

Consistent names

Each file becomes date_supplier_number.xml and goes into its supplier's folder.

Excel report

A spreadsheet in date order, with amounts in reais and a total row built with a formula that updates itself.

Error-proof

A corrupted file is detected and skipped with a warning, without stopping the other invoices.

Technology

Stack and process

Python 3xml.etree.ElementTreepathlibshutilopenpyxltry / exceptFunctionsVS CodeGitHub

I built the program in small steps, running it and checking the result at each one before moving on. At the end, I reorganized everything into functions, wrote the documentation and published the code on GitHub.

Read one invoiceRead them allSort the filesExcel reportHandle errorsFunctions and publishing
Challenges and solutions

What I had to solve

  1. The XML's hidden "surname"

    Every NF-e uses a namespace, an identifier from Brazil's tax authority attached to each tag. Without telling Python about it, the search found no fields at all. Understanding namespaces was the key to reading any invoice.

  2. The leftover cents

    The invoice total came out as 6935.000000000001, because of how computers store decimal numbers. I fixed it by rounding to two decimal places and, in Excel, by writing a sum formula instead of a fixed value.

  3. One broken invoice stopped everything

    I tested the program with a deliberately corrupted file, and it crashed halfway, without building the report for the other invoices. With try and except, the broken file is now logged and skipped, and the rest carries on.

Results

In numbers

10invoices read
5folders created
1command
0originals changed

Results from a run with the sample (fictional) invoices included in the project.

Skills

What this project shows

Automation with Python

Turning a repetitive manual task into a program that runs with one command.

Structured data

Reading and navigating XML, converting text to numbers and sorting.

Reporting

Formatted Excel output with currency, formulas and headers.

Clean code

Functions, error handling, comments and a README explaining how to use it.

“I automated the task I used to do by hand.”

The Organizer was my first Python project, and it brings together both sides of my path: accounting and programming.