Python code for inventory, finance and accounting: six free programs

Python code for inventory, finance and accounting: six free programs
This is the index of the code section. Every program is a Python file commented line by line, with sample data and with the output you should get when you run it: download it, unzip it, run it. There is nothing to install and no account to create, because all six use the Python standard library only.
They are written for people who run a small business and want to understand the numbers, not for people building a system: each file reads end to end in one sitting and can be changed without fear. All six were tested before publishing, and every article explains the code with the real fragments that ship inside the ZIP.
| Program | What it solves | Article |
|---|---|---|
| K1 | the classic stock ledger with weighted-average cost | Python code: weighted-average stock ledger (free download) |
| K2 | the same ledger, valued FIFO and showing which lot left on every sale | Python code: FIFO stock ledger by lots (free download) |
| K3 | all three methods compared on the same movements: FIFO, LIFO and weighted average | Python code: compare FIFO, LIFO and weighted average on the same data |
| C1 | the journal with validated double entry, which rejects any entry that does not tie | Python code: journal with validated double entry (free download) |
| F1 | the loan amortization schedule, instalment by instalment | Python code: loan amortization schedule (free download) |
| R1 | a perceptron from scratch that learns to decide whether a product must be reordered | Python code: perceptron from scratch to decide whether to reorder |
The order that works best
If you have never run a program, start with the weighted-average ledger: it explains the rules of the game (purchases, sales, balance and cost) and the rest read on top of it. Then move to FIFO and to the method comparison, which use the same movements and show how the cost changes with the method. The amortization schedule and the journal belong to the finance and accounting side of the same business, and the perceptron goes last: it is the only one that learns from data instead of applying a formula.
- K1 — the weighted-average stock ledger: the starting point.
- K2 — the same ledger by lots (FIFO), to see which lot left on each sale.
- K3 — all three methods on the same movements, side by side.
- C1 — the journal with double entry, which rejects any entry that does not tie.
- F1 — the loan amortization schedule, instalment by instalment.
- R1 — the perceptron that decides whether a product must be reordered.
What you need to run them
| You need | Detail |
|---|---|
| Python 3.11 or newer | Install it once from the official site and it is available for every program |
| A text editor | The one that ships with your system is enough; if you are going to change the data, one with code highlighting helps |
| Your own data | The CSV file inside the datos folder is enough: open it
in Excel, replace it with your movements and save it the same way |
| Five minutes | None of the six takes longer than that to show a result |
| Extra libraries | None: all six use only what ships with Python |
How to start today
Install Python from the official site, pick the program that solves this week's problem and run
it with your own data: in every case it is enough to replace the CSV file that ships in the
datos folder. If the result is useful, keep it; if not, the file stays where it is and
breaks nothing.
When this is not enough
A script answers one concrete question and answers it well. When the business has several warehouses, several users, invoicing and accounting at the same time, the natural next step is Kardex Tauro, which does that work with screens and with the data stored in a database. Until then, these programs help you understand what is being calculated and keep you away from a spreadsheet that only its author can read.
Questions that always come up
Do I need to know how to program? Not to run them: unzip and run one command. To change a formula or add a column you do need to read the program, and that is what the comment on every line is for.
Can I use them in a real business? Yes, and they work: they are tested before publishing. Keep in mind they are didactic internal-control material: check them against your own figures and the rules that apply to you before making decisions with them.
Why are there no screens like an inventory program? Because a screen costs much more than a file, and the point of this section is that you understand the numbers. When the business grows, the next step is a program with a database and several users, not a bigger script.
What happens to my data? Nothing leaves your computer: no servers, no accounts, no internet involved. The program reads and writes files in your own folder.
All six programs are didactic internal-control material: check them against your own figures before using them in a real business.
Second batch: there are six more programs, same format and also free, in Python code: six more programs for inventory, accounting and databases.