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 ↗
| Date | Supplier | Number | Amount |
|---|---|---|---|
| 2026-10-03 | Papelaria Ipê Amarelo Ltda | 1000 | R$ 193,00 |
| 2026-10-08 | Café Serra Verde Comércio ME | 1008 | R$ 171,00 |
| 2026-10-15 | Tech Minas Informática Ltda | 1016 | R$ 158,90 |
| 2026-10-21 | Limpeza Lagoa Clara EIRELI | 1024 | R$ 439,10 |
| 2026-10-29 | Gráfica Pão de Queijo Ltda | 1032 | R$ 2.670,00 |
| 2026-11-04 | Papelaria Ipê Amarelo Ltda | 1035 | R$ 130,50 |
| 2026-11-10 | Café Serra Verde Comércio ME | 1043 | R$ 94,40 |
| 2026-11-17 | Tech Minas Informática Ltda | 1051 | R$ 709,10 |
| 2026-11-23 | Limpeza Lagoa Clara EIRELI | 1059 | R$ 179,00 |
| 2026-11-27 | Gráfica Pão de Queijo Ltda | 1067 | R$ 2.190,00 |
| TOTAL | TOTAL | R$ 6.935,00 |
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.
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.
From a messy folder to a report
notas/ ├── download.xml ├── NF digitalizada (1).xml ├── nota fiscal novembro.xml ├── nota_cafe.xml ├── nota_estragada.xml └── …
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 └── …
> 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.
Stack and process
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.
What I had to solve
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.
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.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
tryandexcept, the broken file is now logged and skipped, and the rest carries on.
In numbers
Results from a run with the sample (fictional) invoices included in the project.
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.