Repository navigation
v0.2.0: lambda formulas, tracing, versions and review
tracemodel builds financial models in Python where every number has a fixed address, a source you can open, and rules that check it.
pip install pytracemodelHighlights
- One kind of formula. Every formula and check is a lambda of
x. tracemodel checks it against an allow-list and compiles it with RestrictedPython. It saves the lambda as source text, so a model file runs no other code. - Tracing.
model.precedents(...)andmodel.dependents(...)trace a cell, as Excel's Trace Precedents and Trace Dependents do.report.explain()lists each cell a check read. - Versions, branches and review.
tm.Repo.open(path, author)keeps a model in an append-only, hash-chained log. An agent drafts on a branch. A person readsrepo.review(branch), accepts or rejects each change, andrepo.approve(branch)lands only what was accepted.repo.diff(...)shows the calculated cells that moved. - Sources are plain data.
set_value(..., source={...})takes any keys (document,page,bbox,sha256, ...). The Excel Values sheet gets a column for each key. - Text and dates. Items can hold sourced text (
dtype=str) and dates, with pandas-named.strand.dtmethods. - Labels are objects.
dim["Q1"].descriptionanddim["Q1"].attrs. Dimensions have their own description and attrs. - Undo verbs.
remove_item,set_formula,update_item,remove_check,clear_valueandremove_coords. Each one refuses while a formula or a check still reads what it would remove.
Breaking changes from 0.1
- Arithmetic on
model["item"]raisesDefinitionError. Writeformula=lambda x: x["revenue"] * 0.6. - Checks are lambdas of the run
x. Useand,or,notin place of&,|,~. dim.description(label)anddim.attrs(label)are replaced bydim[label].descriptionanddim[label].attrs.- A source no longer requires
document,urlorsection. - Definition files are
tracemodel/2. Files from 0.1 still load.
See CHANGELOG.md for the full list.
Try it: apple.ipynb, a model of Apple's FY2024–FY2025 10-K.