Money & Payments ยท zero-dependency ยท MIT

larznetting

Settle a tangle of debts with the fewest payments.

Nets each person to a single balance, then settles the whole group: the greedy plan clears everyone in at most n-1 payments, and an optimize mode finds the provably minimum number of payments by discovering internally-cancelling groups. Exact integer minor units, so a settlement reconciles to the cent.

larzscript pkg install netting
View on GitHub →Learn the stack

What you get

Try it

import "netting" as netting
let debts = [
  {"from": "alice", "to": "bob", "amount": 1000},
  {"from": "bob", "to": "carol", "amount": 1000},
  {"from": "carol", "to": "alice", "amount": 400}
]
print(netting.settle(debts))
Output
[{from: alice, to: carol, amount: 600}]

Why it's in the Larz Stack

larznetting is a real Larzscript package (larzscript pkg install netting) - money-native, zero dependencies, the same language as the rest of the estate, not a separate Python runtime. It composes with the rest of the Larz Stack and the Larz framework.