tracemodel
tracemodel lets you build a financial model in Python in which every number has a fixed address, a source you can open, and rules that check it. It also gives AI agents a fixed definition to fill: the agent writes values, and the model keeps them consistent and checks them.
pip install pytracemodel # Python 3.12 or later; add "[excel]" for model.to_excel
In 30 seconds. You declare the axes of the model (dimensions), what you measure (items), and enter the numbers (values) with their source. A formula calculates the rest.
import tracemodel as tm
model = tm.Model()
model.add_dimension("period", ["Q1", "Q2"])
model.add_dimension("region", ["north", "south"])
# Items: what we measure, and over which dimensions. profit is calculated, not entered.
model.add_item("revenue", dims=("region", "period"), dtype=float)
model.add_item("cost", dims=("region", "period"), dtype=float)
model.add_item("profit", dims=("region", "period"), dtype=float, formula=lambda x: x["revenue"] - x["cost"])
# Facts: each number is entered with where it came from.
source = {"document": "Q2 sales report", "page": 4}
facts = {("north", "Q1"): (700, 450), ("north", "Q2"): (760, 480),
("south", "Q1"): (500, 320), ("south", "Q2"): (545, 350)}
for (region, period), (revenue, cost) in facts.items():
model.set_value("revenue", {"region": region, "period": period}, revenue, source)
model.set_value("cost", {"region": region, "period": period}, cost, source)
# Read it back.
model.get("profit", region="north", period="Q2") # 280, calculated from revenue and cost
model.entry("revenue", region="north", period="Q2").source # {'document': 'Q2 sales report', 'page': 4}
model.table("profit") # regions down, periods across:
# profit
# region Q1 Q2
# north 250 280
# south 180 195
You can also declare rules the numbers must obey, such as "the total equals North + South". The model checks them and shows which numbers broke a rule (Data quality). A complete model is built step by step in the Example, and Apple's FY2024–FY2025 10-K runs in Colab.
Compared with Excel and pandas.
| Excel | pandas / xarray | tracemodel | |
|---|---|---|---|
| Source on each number | no | no | yes: document, page, any keys |
| Formulas | per cell, can be overwritten with no trace | code, not stored with the data | per item or per cell, saved as text and traced |
| Checks that run on every period | manual | manual | declared once, run per label |
| Trace a number to its inputs | Trace Precedents | no | precedents(), dependents(), explain() |
| Version control and review | no | no | commits, branches, accept or reject per value |
| AI agent writes values | free-form | free-form | validated against a fixed definition |
| Output to Excel | — | yes | yes: to_excel() |
Keeping models. tracemodel.store.open_store(path, write=True) keeps named models in one file. A page of a large model is a
seek, a write recalculates only the cells it reaches, and a log lets you rebuild the file. See
Saving and loading.
Documentation
datayoga-io.github.io/tracemodel: Concepts, Example, Model reference, Data quality, Formulas, Dates, text and missing values, Tracing and errors, Saving and loading, Versions, branches and review, Working with AI agents, Changelog.
Contributing: CONTRIBUTING.md. Licensed under Apache 2.0.
Metadata
Release files for pytracemodel 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytracemodel-0.4.0.tar.gz | 382.2 kB | Without provenance | Details for pytracemodel-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytracemodel-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for pytracemodel-0.4.0-py3-none-any.whl |
Total release size: 534.3 kB
Release files / pytracemodel-0.4.0.tar.gz
| Download URL | pytracemodel-0.4.0.tar.gz |
|---|---|
| Size | 382.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a28389cf0cff343b645a02ca3ecbcf55bc019061e291df6b354a6e7a1dace00
|
|
BLAKE2b-256 checksum How to use checksums |
36934233d013835d5b300be5893b6261482192d66bd63ef4dd8738b9ca66db9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pytracemodel-0.4.0-py3-none-any.whl
| Download URL | pytracemodel-0.4.0-py3-none-any.whl |
|---|---|
| Size | 152.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0c6710b7dbf489c5c0cf081094bf6c53ccba7bef519940c61fb7498e54121b4
|
|
BLAKE2b-256 checksum How to use checksums |
7e14da6b9eea406d8ac22a99d7169b8d73a1e4f6645b537cbf61e57bee12ce8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pytracemodel 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.