Money & Payments — Handling Money Correctly
Money is where sloppy code costs real cash. This family of the stack does money the right way: exact values, double-entry ledgers, real invoices, and subscription billing.
The single most common money bug in software is using a floating-point number for currency — where 0.1 + 0.2 famously isn't 0.3. The Larz Stack's money family refuses to make that mistake, and builds up from there: exact money, books that always balance, professional invoices, and subscription logic you don't have to hand-roll.
The money family
Four libraries cover most of what a money-handling app needs.
| Library | What it does |
|---|---|
| larzmoney | Exact money as integer minor units + currency — never a float |
| larzledger | Double-entry accounting: postings that must balance, trial balance |
| larzpdf | Generate real PDF invoices & receipts with exact, aligned totals |
| larzsubscription | Billing state machine: trials, renewals, dunning, proration, cancel |
Notice the layering: exact values (larzmoney) become entries in books (larzledger), documents (larzpdf), and recurring billing (larzsubscription).
Exact money in practice
larzmoney stores money as whole minor units (cents) with a currency, so arithmetic is always exact and splitting never loses or invents a penny.
from larzmoney import Money
bill = Money("100.00", "USD")
shares = bill.split(3) # exact 3-way split
# [$33.34, $33.33, $33.33] — sums back to $100.00, no lost cent
Money("0.1","USD") + Money("0.2","USD") # == $0.30 exactlysplit() guarantees the parts always reconcile to the whole.From values to a business
Stack the money libraries and you have a real billing backend.
| Need | Reach for |
|---|---|
| Charge exact amounts, split bills | larzmoney |
| Keep books that always balance | larzledger |
| Send an invoice or receipt | larzpdf |
| Run monthly plans with trials | larzsubscription |
Each is independent, but together they cover the money layer of most SaaS and marketplace apps — and all of it plugs into the Larz framework (Session 6).
🎯 Key takeaways
- The money family: larzmoney (exact money), larzledger (double-entry), larzpdf (invoices), larzsubscription (billing).
- larzmoney stores money as integer minor units — arithmetic is exact and split() always reconciles.
- Never use floats for currency; rounding errors accumulate until books don't balance.
- Layered together, these cover the money backend of most SaaS and marketplace apps.
Frequently asked
Why not just use Python's Decimal?
Decimal fixes float inaccuracy and larzmoney uses exact arithmetic under the hood, but money is more than a number — it has a currency, needs safe splitting/allocation that reconciles, formatting, and rounding rules. larzmoney wraps all of that into a money type that refuses invalid operations (like adding two different currencies), so the correctness is enforced, not left to you to remember.
Do these work with real payment providers?
The money libraries handle the money logic — exact amounts, ledgers, invoices, subscription state. Actually moving money happens through a payment provider, which the Larz framework's provider layer handles (Stripe, GemVault, crypto, etc.). You keep your money math exact and provider-agnostic, and swap the checkout backend without touching your billing logic.
Related lessons
What the Larz Stack Is (and Why Zero-Dependency)
Modern software drowns in dependencies — hundreds of packages you never read, each a risk.…
Building with the Larz StackData & Storage — Persisting Without a Server
Most apps don't need a database server on day one. This family gives you crash-safe storag…
Building with the Larz StackPutting It Together with the Larz Framework
The libraries shine alone — but they were also designed to click into the Larz web framewo…