Skip to main content

tracemodel

PyPI Python License Docs Open In Colab

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()

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.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytracemodel 0.3.0
File Size Uploaded Provenance Actions
pytracemodel-0.3.0.tar.gz 301.7 kB Without provenance Details for pytracemodel-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytracemodel 0.3.0
File Interpreter ABI Platform Actions
pytracemodel-0.3.0-py3-none-any.whl Python 3 none any Details for pytracemodel-0.3.0-py3-none-any.whl

Total release size: 405.9 kB

Release files / pytracemodel-0.3.0.tar.gz

Download URL pytracemodel-0.3.0.tar.gz
Size 301.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9e5b6eb36dd7b051b26b5ae88935df9dfacbe9c04198e524703204216e32907e
BLAKE2b-256 checksum
How to use checksums
effc5925f251893638018d57e983ddb7d376f2df38e0136fff81ca1f7de3aa36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","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.3.0-py3-none-any.whl

Download URL pytracemodel-0.3.0-py3-none-any.whl
Size 104.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a58cc52abc1e04138ee914351320e2fcdf31a5b2d31964583a6e0a743008ffa
BLAKE2b-256 checksum
How to use checksums
ac04dc4f43d51fdcd5bf5aea9e40f11a9c255d87035492fde7ab1b7f7e04ca91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","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.3.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page