Changelog¶
Changelog¶
Unreleased¶
0.4.0 — 2026-11-29¶
- A persistent store:
tracemodel.store.open_store(path, write=True)keeps named models in one file. A write recalculates only the cells it reaches, so a page of a large model is a seek, and each write is also logged so the file can be rebuilt. The cells sit behind aLayoutinterface that another arrangement can fill in (it uses orjson, now a dependency, for fast loads;pip install --no-deps pytracemodel restrictedpythonruns without it, with the same results). See the saving guide.
0.3.0 — 2026-11-23¶
-
Yes/no items:
add_item(..., dtype=bool)(or"bool") holdsTrueorFalse.set_valuerejects anything else, so a flag can no longer be2; a formula or check uses it as a plainbool(if x["firm"],expect=lambda x: x["firm"]); tables showyesandno; it is saved astrueandfalse. When the source does not say, entertm.NIL, which is notFalse. Before, a flag had to be anintitem of0and1. Closes #43. -
model.cells()reads many cells at once:model.cells(use="offices")returns aTablewith one row per cell (item,coords,value,kind,source) for every item that has that dim;model.cells(["fee", "rate"])reads named items in full, scalars included. A cell with no value ismissingand does not raise, so one gap no longer stops a read of the rest. Before, reading across items took onegetorentryper item. -
A source is free plain data, and optional:
set_value(..., source=None)takes a dict with any keys (page,bbox,sha256, ...) whose values are text, numbers, true/false, none, lists and dicts of those, so structured facts no longer need packing intosectionas text. It is copied, saved and reloaded as it was. The Excel Values sheet gets a column per extra key. Breaking:document,urlandsectionare no longer required and unknown keys are no longer rejected; a source that isn't plain data (a date object, say) raisesInvalidValue. A schema for sources and a policy on them are on the backlog. -
Labels are objects:
dim["PA"]returns atm.Label, astrthat also knows its.description, its read-only.attrsand its.dimension;dim.labelslists them. It compares, hashes and prints as its code, so it goes wherever a label string does, anddim.coordsstays plain text. - Dimension description and attrs: a dimension has its own
description(what people call it, "Unit type"; the name stays what formulas use) andattrs(free-form facts about it), like an item and a label:add_dimension(name, coords, description=..., attrs=...)andupdate_dimension(name, description=..., attrs=...). Saved with the model and versioned (dimension.update). Breaking:dim.description(label)anddim.attrs(label)are gone; usedim[label].descriptionanddim[label].attrs. - Review: an agent drafts on a branch (a repo opened with
self_approve=False); a person reads it withrepo.review(branch)(each change with its author, and the calculated cells it moves), changes it on the branch, rules withrepo.accept/reject/commenton a cell, a slice, an item, a commit or all of it, and lands what was accepted withrepo.approve(branch), which re-runs the checks. Nobody approves their own changes;repo.approved_by(...)says who let a value in. - Diff:
repo.diff(a, b, calculated=True)andtm.diff(model_a, model_b)list the definitions and entered values that differ, and the calculated cells that moved, each naming the differing inputs and formulas it rests on. - Branches:
repo.new_branch,checkout,branches,drop_branch, andrepo.rebase(branch, onto), which lands a branch's changes on another as one commit, checked by the model's verbs, or refuses naming every object both sides changed differently (repo.conflicts). History stays a line.repo.attakes a branch name. - Versions:
tm.Repo.open(path, author)keeps a model under version control in an append-only log.repo.modelis the branch's model;repo.commit(message)writes its pending changes as one commit,repo.discard()drops them.repo.log(),repo.at(commit)(the model at a commit, read-only),repo.history(item, **coords)andrepo.export(...)read it back. The log's records are checksummed and hash-chained; a torn last line and a second writer are caught. - Recording changes:
with model.recording() as ops:records every change as atm.Opof plain data, whichtm.ops.replayapplies to another model through the same verbs andtm.ops.invertundoes. - Verbs that undo:
remove_item,set_formula,update_item,remove_check,clear_valueandremove_coords. Each refuses, with nothing changed, while a formula or a check still reads what it would remove; in a transaction that is checked at commit. - Text items:
add_item(..., dtype=str)(or"str"/"string") holds sourced text, such as a contract's status or vendor. Text compares and joins in formulas and checks,.strgives pandas-named methods (contains,lower,len, ...), empty text is rejected in favour oftm.NIL, and Excel writes it as text. Comparing text with a number now raisesDefinitionErrorinstead of beingFalseor aTypeError. to_excelnests every dim down in the first column, as a pivot table's compact form.- 52/53-week fiscal years:
tm.period_range(..., freq="Y-SEP-SAT-LAST")(Apple's, ending on the last Saturday of September) or"Y-JAN-SAT-NEAREST"(retail), as pandas'FY5253, and 13-week quarters,"Q-SEP-SAT-LAST", with the 53rd week in the first quarter or the one named ("Q-JAN-SAT-NEAREST-4").start_time,end_time,days,inandoverlapuse the weeks.
0.2.0 — 2026-10-15¶
One kind of formula. Every formula and check is a lambda of x, checked against an allow-list
and compiled with RestrictedPython, the new
and only dependency.
Breaking
- Arithmetic and comparisons on
model["item"]raiseDefinitionError, showing the lambda to write:formula=model["revenue"] * 0.6becomesformula=lambda x: x["revenue"] * 0.6, andexpect=model["a"] >= 0becomesexpect=lambda x: x["a"] >= 0.model["item"]still selects cells and shows them as a table. - Checks are lambdas of the run,
x. A function whose parameters are dims (lambda region: ...) is refused; a rollup readsx.children(dim). and,or,notand chained comparisons replace&,|and~.- A
defformula is refused: a formula is one lambda. tracemodel.text,Conditionand the expression classes are removed, withCheck.paramsandCheck.conditions.- Closure values must be data (numbers, strings, lists and dicts of them, dates); a closure over the model or a cell is refused when the formula is added. They are copied then, so changing them later doesn't change the formula.
- A formula may use only the allow-listed Python (see "What a formula may use" in the README).
A 0.1
{"python": ...}formula outside it, or one that used the model, an expression or a module other thanmath, must be rewritten as a lambda ofx. - A lambda's source is read when it is added; one with no source file (typed at a plain
pythonprompt, built withexec) raises: pass its text instead. Check.condition()is removed. A check over a dict of lambdas (LINES[x.coords[...]](x)) becomes oneif/elselambda.- Definition files are
"format": "tracemodel/2", with formulas saved as lambdas; 0.2 readstracemodel/1files too, and 0.1 refusestracemodel/2.
New
model.precedents(item, deep=False, **coords)andmodel.dependents(...), as Excel's Trace Precedents and Trace Dependents, found from the formulas' source.- Every formula is checked when added: unknown items and labels, open dims and circular formulas, with both arms of a branch counted. Inside a transaction, at commit, so a formula may read an item added later.
x.children(dim),x.parent(dim)andx.labels(dim);int(x["n"]).tm.load(path, formulas="off")loads a file without compiling or running its formulas.tm.Formulaandtm.Trace.
Files
- Formulas and checks are saved as their lambda's source,
"formula": "lambda x: ...", with"env"for the values they use. Loading needs noallow_code; the argument is ignored with aDeprecationWarning. - Files from 0.1 load: expression text (with
date('...')constants),expect_by_labelchecks and{"python": ...}entries that keep to the allow-list are converted to lambdas.