redroot 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- redroot-0.2.0/.gitignore +210 -0
- redroot-0.2.0/CHANGELOG.md +89 -0
- redroot-0.2.0/LICENSE +21 -0
- redroot-0.2.0/PKG-INFO +309 -0
- redroot-0.2.0/README.md +262 -0
- redroot-0.2.0/pyproject.toml +159 -0
- redroot-0.2.0/src/redroot/__init__.py +71 -0
- redroot-0.2.0/src/redroot/_core.py +556 -0
- redroot-0.2.0/src/redroot/cli.py +98 -0
- redroot-0.2.0/src/redroot/functions.py +240 -0
- redroot-0.2.0/src/redroot/instrument.py +614 -0
- redroot-0.2.0/src/redroot/ops.py +332 -0
- redroot-0.2.0/src/redroot/paths.py +162 -0
- redroot-0.2.0/src/redroot/propagation.py +447 -0
- redroot-0.2.0/src/redroot/py.typed +0 -0
- redroot-0.2.0/src/redroot/serialization.py +245 -0
- redroot-0.2.0/src/redroot/trace.py +474 -0
- redroot-0.2.0/src/redroot/types.py +385 -0
- redroot-0.2.0/src/redroot/validation.py +221 -0
- redroot-0.2.0/src/redroot/visualizer/__init__.py +11 -0
- redroot-0.2.0/src/redroot/visualizer/data.py +63 -0
- redroot-0.2.0/src/redroot/visualizer/graphviz.py +44 -0
- redroot-0.2.0/src/redroot/visualizer/networkx.py +36 -0
- redroot-0.2.0/src/redroot/visualizer/web/__init__.py +1 -0
- redroot-0.2.0/src/redroot/visualizer/web/server.py +52 -0
- redroot-0.2.0/src/redroot/visualizer/web/static/app.js +125 -0
- redroot-0.2.0/src/redroot/visualizer/web/static/index.html +38 -0
- redroot-0.2.0/src/redroot/visualizer/web/static/style.css +49 -0
- redroot-0.2.0/tests/__init__.py +0 -0
- redroot-0.2.0/tests/conftest.py +13 -0
- redroot-0.2.0/tests/helpers.py +37 -0
- redroot-0.2.0/tests/test_cli.py +68 -0
- redroot-0.2.0/tests/test_docs.py +47 -0
- redroot-0.2.0/tests/test_functions.py +129 -0
- redroot-0.2.0/tests/test_instrument.py +312 -0
- redroot-0.2.0/tests/test_paths.py +73 -0
- redroot-0.2.0/tests/test_propagation.py +198 -0
- redroot-0.2.0/tests/test_properties.py +156 -0
- redroot-0.2.0/tests/test_pydantic.py +49 -0
- redroot-0.2.0/tests/test_regressions.py +278 -0
- redroot-0.2.0/tests/test_serialization.py +133 -0
- redroot-0.2.0/tests/test_trace.py +151 -0
- redroot-0.2.0/tests/test_types.py +209 -0
- redroot-0.2.0/tests/test_validation.py +71 -0
- redroot-0.2.0/tests/test_visualizers.py +53 -0
redroot-0.2.0/.gitignore
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
# Example output
|
|
210
|
+
graph_demo.json
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-10-02
|
|
11
|
+
|
|
12
|
+
Re-evaluable traces: RedRoot now answers "what does every output become if
|
|
13
|
+
this input changes?" without re-running the code, and says when it cannot.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- `Trace`: a per-run recording, used as a context manager, with inputs
|
|
17
|
+
(`track`, `leaf`) and outputs (`collect`, `output`) keyed by semantic
|
|
18
|
+
paths such as `ext:bank.line_items[3].amount`; `run()` helper.
|
|
19
|
+
- Navigation: `sources()`, `ancestors()`, `descendants()`, `dependents()`,
|
|
20
|
+
`explain()`.
|
|
21
|
+
- Forward propagation: `Trace.propagate()` returns per-output
|
|
22
|
+
`UNCHANGED`/`UPDATED`/`STALE`/`UNLINKED` statuses with reasons, with early
|
|
23
|
+
cutoff, and `Propagation.verify()` compares against a re-execution.
|
|
24
|
+
- Guards: comparisons, truth tests, `int()`/`float()`/`hash()`/`len()` and
|
|
25
|
+
container shapes are recorded and re-checked during propagation.
|
|
26
|
+
- `TracedDecimal`; `round()`, `math.floor/ceil/trunc`, `format()`, `str()`,
|
|
27
|
+
`divmod()`, `str` and `Decimal` methods stay traced; results that are
|
|
28
|
+
lists, tuples or dicts are traced item by item.
|
|
29
|
+
- `@traced` (one re-callable node per call), `@traced_llm`, `annotate()`,
|
|
30
|
+
`derive()`.
|
|
31
|
+
- `redroot.instrument`: source rewriting that traces what operator
|
|
32
|
+
overloading cannot see (`0.8 * traced_int`, `float(text)`, f-strings,
|
|
33
|
+
`", ".join(...)`, indexing with traced ints).
|
|
34
|
+
- `redroot.validation`: `coverage()`, `check_identity()`,
|
|
35
|
+
`check_perturbation()`.
|
|
36
|
+
- Versioned JSON serialization (`to_json`/`from_json`); CLI commands
|
|
37
|
+
`explain` and `coverage`; web viewer highlights an output's lineage.
|
|
38
|
+
- `docs/design.md`, `docs/integration.md`, `AGENTS.md`, `SECURITY.md`,
|
|
39
|
+
a tracing-overhead benchmark.
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
- **Renamed from RedThread to RedRoot.** The name `redthread` on PyPI belongs
|
|
43
|
+
to an unrelated project, so the package is now `pip install redroot` and
|
|
44
|
+
`import redroot`; the command-line tool is `redroot`, and the trace format
|
|
45
|
+
is identified as `redroot.trace`.
|
|
46
|
+
- **Breaking:** nodes are lightweight objects with integer ids, owned by a
|
|
47
|
+
`Trace`; operations are recorded only inside an active trace (outside one,
|
|
48
|
+
traced values behave like plain values).
|
|
49
|
+
- **Breaking:** every operand is recorded in order, constants included.
|
|
50
|
+
- Pydantic is now an optional extra (`redroot[pydantic]`); the core has no
|
|
51
|
+
dependencies.
|
|
52
|
+
- About 8x faster per traced operation than 0.1.0.
|
|
53
|
+
|
|
54
|
+
### Removed
|
|
55
|
+
- **Breaking:** `LineageGraph`, `TracedValue`, `get_context()`,
|
|
56
|
+
`lineage_context()`, `transform()` and `trace()`, superseded by `Trace`,
|
|
57
|
+
`annotate()` and `explain()`.
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
- Mixed-type arithmetic returned wrong values (`TracedInt(5) + 1.5 == 6`).
|
|
61
|
+
- `TracedInt / 2` dropped tracing.
|
|
62
|
+
- `transform()` and `@traced_llm` raised `TypeError`.
|
|
63
|
+
- `lineage_context()` did not isolate recorded nodes; the global registry
|
|
64
|
+
grew without bound.
|
|
65
|
+
- Passing a traced value through a Pydantic model severed its lineage.
|
|
66
|
+
- The web viewer inserted trace values into the page as HTML.
|
|
67
|
+
- Soundness gaps found by adversarial review, where propagation reported an
|
|
68
|
+
exact value that re-execution contradicted: exceptions caught by
|
|
69
|
+
`try`/`except` (now recorded as guards), `decimal.localcontext()` (each
|
|
70
|
+
`Decimal` node keeps its context), intermediate values changing type,
|
|
71
|
+
`@traced` helpers sharing a name, inputs reaching `@traced` functions
|
|
72
|
+
through sets, dict views or closures, `hash(-1) == hash(-2)`, and, under
|
|
73
|
+
instrumentation, `bisect`/`sorted`/`heapq` with plain floats, `min`/`max`
|
|
74
|
+
with closure keys, `map(float, ...)`, `sum(gen, start)`, unbound
|
|
75
|
+
`str` methods, `repr`, f-strings of containers, and opaque library calls
|
|
76
|
+
such as `date.fromisoformat` (now guarded).
|
|
77
|
+
- `apply_edits()` failed on tuple inputs.
|
|
78
|
+
|
|
79
|
+
### Security
|
|
80
|
+
- The web viewer renders trace content as text only.
|
|
81
|
+
|
|
82
|
+
## [0.1.0] - 2026-01-24
|
|
83
|
+
|
|
84
|
+
Prototype, not published to PyPI.
|
|
85
|
+
|
|
86
|
+
### Added
|
|
87
|
+
- `TracedInt`, `TracedFloat`, `TracedStr`, a lineage graph
|
|
88
|
+
with JSON export, LLM transformation tracking, Pydantic integration,
|
|
89
|
+
GraphViz/NetworkX export and a web visualizer.
|
redroot-0.2.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gagan Gaurav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
redroot-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: redroot
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Value-level lineage for Python: trace where every output came from, and propagate input edits to every output without re-running
|
|
5
|
+
Project-URL: Homepage, https://github.com/gagan-gaurav/redthread
|
|
6
|
+
Project-URL: Documentation, https://github.com/gagan-gaurav/redthread#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/gagan-gaurav/redthread
|
|
8
|
+
Project-URL: Issues, https://github.com/gagan-gaurav/redthread/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/gagan-gaurav/redthread/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Gagan Gaurav
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: audit,dag,data-engineering,data-provenance,incremental-computation,lineage,llm,provenance,pydantic,tracing
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: flask>=3.0; extra == 'all'
|
|
29
|
+
Requires-Dist: graphviz>=0.20; extra == 'all'
|
|
30
|
+
Requires-Dist: networkx>=3.0; extra == 'all'
|
|
31
|
+
Requires-Dist: pydantic>=2.0; extra == 'all'
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: hypothesis>=6.100; extra == 'dev'
|
|
34
|
+
Requires-Dist: mypy==2.3.1; extra == 'dev'
|
|
35
|
+
Requires-Dist: pre-commit>=3.0; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
38
|
+
Requires-Dist: ruff==0.16.10; extra == 'dev'
|
|
39
|
+
Provides-Extra: pydantic
|
|
40
|
+
Requires-Dist: pydantic>=2.0; extra == 'pydantic'
|
|
41
|
+
Provides-Extra: viz
|
|
42
|
+
Requires-Dist: graphviz>=0.20; extra == 'viz'
|
|
43
|
+
Requires-Dist: networkx>=3.0; extra == 'viz'
|
|
44
|
+
Provides-Extra: web
|
|
45
|
+
Requires-Dist: flask>=3.0; extra == 'web'
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
|
|
48
|
+
<div align="center">
|
|
49
|
+
|
|
50
|
+
# <img width="128" height="128" alt="RedRoot logo" src="https://github.com/user-attachments/assets/82d895e5-a7ba-447e-a3dc-dfeb36c4c1dd" /> RedRoot
|
|
51
|
+
### Trace Every Value to Its Roots
|
|
52
|
+
|
|
53
|
+
[](https://github.com/gagan-gaurav/redthread/actions/workflows/ci.yml)
|
|
54
|
+
[](https://pypi.org/project/redroot/)
|
|
55
|
+
[](https://pypi.org/project/redroot/)
|
|
56
|
+
[](https://opensource.org/licenses/MIT)
|
|
57
|
+
|
|
58
|
+
**RedRoot** records how every value in a Python computation was produced, at the level of individual values, so you can ask, in both directions:
|
|
59
|
+
|
|
60
|
+
**Where did this output come from?** · **What does every output become if this input changes?**
|
|
61
|
+
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
Run a computation once under RedRoot and you get a graph from inputs to outputs. Click a number that looks wrong and see the exact inputs and arithmetic behind it. Correct one input and every output that used it is recomputed from the graph, instantly and together, without running your code again. When the graph cannot be sure (a branch would go the other way, an LLM call would need re-running), RedRoot says so instead of guessing.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import redroot as rr
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def workflow(ext):
|
|
73
|
+
a, b = ext["A"], ext["B"]
|
|
74
|
+
return {
|
|
75
|
+
"form1": {"line_12": a + b},
|
|
76
|
+
"form2": {"line_7": a * b},
|
|
77
|
+
"table3": {"amount": a},
|
|
78
|
+
"table4": {"total": b},
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
trace, _ = rr.run(workflow, {"A": 1200, "B": 300}, input_root="ext")
|
|
83
|
+
|
|
84
|
+
print(trace.sources("out:form1.line_12")) # [<Node #0 leaf ext:A=1200>, <Node #1 leaf ext:B=300>]
|
|
85
|
+
print(trace.explain("out:form2.line_7")) # ext:A * ext:B
|
|
86
|
+
print(trace.dependents("ext:A")) # ['out:form1.line_12', 'out:form2.line_7', 'out:table3.amount']
|
|
87
|
+
|
|
88
|
+
result = trace.propagate({"ext:A": 1300})
|
|
89
|
+
for key, change in result.outputs.items():
|
|
90
|
+
print(key, change.status.value, change.old, "->", change.new)
|
|
91
|
+
# out:form1.line_12 updated 1500 -> 1600
|
|
92
|
+
# out:form2.line_7 updated 360000 -> 390000
|
|
93
|
+
# out:table3.amount updated 1200 -> 1300
|
|
94
|
+
# out:table4.total unchanged 300 -> 300
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Features
|
|
98
|
+
|
|
99
|
+
- **Drop-in traced values.** `TracedInt`, `TracedFloat`, `TracedDecimal` and `TracedStr` are real `int`/`float`/`Decimal`/`str` instances. Results, types and errors are exactly those of plain Python.
|
|
100
|
+
- **Re-evaluable graph.** Every operand is recorded in order, constants included, so any node can be recomputed, not just read.
|
|
101
|
+
- **Guards.** Comparisons, branches, conversions and lookups are recorded. If an edit would change one, every output is reported `stale` rather than shown with a value that may be wrong.
|
|
102
|
+
- **Semantic keys.** Inputs and outputs are named by their path, e.g. `ext:bank.line_items[3].amount`.
|
|
103
|
+
- **No cooperation needed from the code.** Tracing happens through operator overloading. For code you run from source, such as generated code, `redroot.instrument` closes the remaining gaps.
|
|
104
|
+
- **Re-execution as the arbiter.** Built-in tools compare the graph's answers with a real re-run, and measure coverage on your workloads.
|
|
105
|
+
- **Opaque steps.** `@traced` turns a function (a tax-table lookup, a geocoder) into one re-callable node. `@traced_llm` marks LLM calls as not replayable.
|
|
106
|
+
- **Persistable.** Traces serialize to versioned JSON, ship with a CLI, and come with a web viewer plus GraphViz and NetworkX exports.
|
|
107
|
+
- **Zero dependencies** in the core. Pydantic, visualization and the web viewer are optional extras.
|
|
108
|
+
|
|
109
|
+
## Installation
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install redroot # core, no dependencies
|
|
113
|
+
pip install "redroot[pydantic]" # traced types as Pydantic fields
|
|
114
|
+
pip install "redroot[viz,web]" # GraphViz/NetworkX exports and the web viewer
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Python 3.10 or newer is required.
|
|
118
|
+
|
|
119
|
+
## Guide
|
|
120
|
+
|
|
121
|
+
### Recording a trace
|
|
122
|
+
|
|
123
|
+
Operations on traced values are recorded while a `Trace` is active. Outside one, traced values behave exactly like plain values and nothing is recorded, so nothing accumulates in long-running processes.
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from decimal import Decimal
|
|
127
|
+
import redroot as rr
|
|
128
|
+
|
|
129
|
+
extracted = {"bank": {"balance": Decimal("12450.00"), "fee": Decimal("12.50")}, "married": True}
|
|
130
|
+
|
|
131
|
+
with rr.Trace("run-42") as trace:
|
|
132
|
+
ext = trace.track(extracted, root="ext") # traced copy; inputs keyed by path
|
|
133
|
+
net = ext["bank"]["balance"] - ext["bank"]["fee"] * 12
|
|
134
|
+
trace.collect({"summary": {"net": net, "year": 2025}}, root="out")
|
|
135
|
+
|
|
136
|
+
print(list(trace.inputs)) # ['ext:bank.balance', 'ext:bank.fee']
|
|
137
|
+
print(trace.explain("out:summary.net")) # ext:bank.balance - (ext:bank.fee * 12)
|
|
138
|
+
|
|
139
|
+
# bool and None cannot be traced; such inputs are listed instead:
|
|
140
|
+
print(dict(trace.untracked_inputs)) # {'ext:married': True}
|
|
141
|
+
|
|
142
|
+
# 2025 was not computed from any input:
|
|
143
|
+
print(trace.outputs["out:summary.year"].linked) # False
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`rr.run(workflow, inputs, input_root=..., output_root=...)` does the `track`, call and `collect` steps for you.
|
|
147
|
+
|
|
148
|
+
### Navigating backwards and forwards
|
|
149
|
+
|
|
150
|
+
| Question | Call |
|
|
151
|
+
|---|---|
|
|
152
|
+
| Which inputs produced this output? | `trace.sources("out:form1.line_12")` |
|
|
153
|
+
| Show me the computation. | `trace.explain("out:form1.line_12")` |
|
|
154
|
+
| Which outputs use this input? | `trace.dependents("ext:A")` |
|
|
155
|
+
| Every node involved | `trace.ancestors(...)`, `trace.descendants(...)` |
|
|
156
|
+
|
|
157
|
+
### Propagating an edit
|
|
158
|
+
|
|
159
|
+
`trace.propagate(edits)` re-evaluates only the nodes downstream of the edited inputs and reports, for every output:
|
|
160
|
+
|
|
161
|
+
| Status | Meaning |
|
|
162
|
+
|---|---|
|
|
163
|
+
| `UPDATED` | New value, computed exactly from the graph. |
|
|
164
|
+
| `UNCHANGED` | The edit does not affect this output. |
|
|
165
|
+
| `STALE` | The graph cannot be sure. Re-execute to get the value. |
|
|
166
|
+
| `UNLINKED` | The output is not linked to any traced input. |
|
|
167
|
+
|
|
168
|
+
The graph is only trusted while execution would follow the same path. Branches are the case a pure graph gets wrong:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
def guarded(ext):
|
|
172
|
+
a, b = ext["A"], ext["B"]
|
|
173
|
+
line_12 = a + b if a > 1000 else 0
|
|
174
|
+
return {"line_12": line_12, "other": b * 2}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
trace, _ = rr.run(guarded, {"A": 1200, "B": 300}, input_root="ext")
|
|
178
|
+
|
|
179
|
+
print(trace.propagate({"ext:A": 1100}).exact) # True
|
|
180
|
+
|
|
181
|
+
result = trace.propagate({"ext:A": 800}) # A > 1000 no longer holds
|
|
182
|
+
print(result.exact) # False
|
|
183
|
+
print(result.reasons[0].message) # ext:A > 1000 was True, now False
|
|
184
|
+
print(result.outputs["out:other"].status.value) # stale
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
When a guard flips, *every* output is reported stale, not just those computed under the branch. A trace only records the path that ran: writes on the other path are invisible to it, so no output can be vouched for. See [docs/design.md](docs/design.md#why-a-flipped-guard-makes-every-output-stale).
|
|
188
|
+
|
|
189
|
+
Exceptions count as branches too: an operation that raised (and was caught) is recorded with its outcome, so an edit that makes it stop raising flips it. Other reasons for re-execution include an edit to an untracked input, a value that changes type, an operation that would now raise, and an input change reaching a non-replayable step. Each is reported in `result.reasons`.
|
|
190
|
+
|
|
191
|
+
### Verifying with re-execution
|
|
192
|
+
|
|
193
|
+
Re-execution on the edited inputs is the source of truth. The graph is the instant path.
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
inputs = {"A": 1200, "B": 300}
|
|
197
|
+
edits = {"ext:A": 1100}
|
|
198
|
+
trace, _ = rr.run(guarded, inputs, input_root="ext")
|
|
199
|
+
result = trace.propagate(edits)
|
|
200
|
+
|
|
201
|
+
retrace, _ = rr.run(guarded, rr.apply_edits(inputs, edits, root="ext"), input_root="ext")
|
|
202
|
+
assert result.verify(retrace.output_values()).ok
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
A mismatch on an output the graph claimed to know is a tracing gap. `redroot.validation.check_perturbation` runs this experiment in one call.
|
|
206
|
+
|
|
207
|
+
### Lookups, external services and LLM calls
|
|
208
|
+
|
|
209
|
+
Decorate a step to record each call as one node. Deterministic functions are re-called during propagation; the others keep their recorded result until their inputs change.
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
@rr.traced(name="irs.national_standard")
|
|
213
|
+
def national_standard(household_size: int) -> Decimal:
|
|
214
|
+
return {1: Decimal("785"), 2: Decimal("1410"), 3: Decimal("1617")}[household_size]
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@rr.traced(name="geo.county", deterministic=False) # e.g. a web lookup
|
|
218
|
+
def county_for_zip(zip_code: str) -> str:
|
|
219
|
+
return "Travis"
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@rr.traced_llm(model="gpt-4o", task="summarize")
|
|
223
|
+
def summarize(text: str) -> str:
|
|
224
|
+
rr.annotate(prompt_tokens=len(text) // 4) # stored on the node
|
|
225
|
+
return text[:40]
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
with rr.Trace() as trace:
|
|
229
|
+
size = trace.leaf(3, "ext:household_size")
|
|
230
|
+
trace.output("out:allowance", national_standard(size) * 12)
|
|
231
|
+
|
|
232
|
+
print(trace.propagate({"ext:household_size": 2}).outputs["out:allowance"].new) # 16920
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
For results computed elsewhere, `rr.derive(value, inputs, "op-name")` records the link manually.
|
|
236
|
+
|
|
237
|
+
### Running generated or untrusted-shape code: instrumentation
|
|
238
|
+
|
|
239
|
+
Operator overloading cannot see everything. CPython computes `0.8 * income` (a plain `float` times a traced `int`), `float(text)`, `", ".join(parts)` and `sorted([income, 20000.5])` in C, without consulting the traced value, so those results would lose their lineage. For code you execute from source, `exec_source` rewrites the syntax tree first (as pytest does for `assert`) and closes these gaps. Calls into code it cannot see into (`date.fromisoformat`, `json.dumps`, third-party libraries) that consume traced values but return none are guarded, so editing their inputs requires re-execution rather than producing a stale value:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from redroot.instrument import exec_source
|
|
243
|
+
|
|
244
|
+
generated = """
|
|
245
|
+
def main(ext):
|
|
246
|
+
gross = float(ext["gross"].replace(",", ""))
|
|
247
|
+
return {"net": 0.8 * gross, "label": f"{gross:,.2f} USD"}
|
|
248
|
+
"""
|
|
249
|
+
namespace = exec_source(generated)
|
|
250
|
+
trace, _ = rr.run(namespace["main"], {"gross": "5,200.50"}, input_root="ext")
|
|
251
|
+
print(trace.explain("out:net")) # 0.8 * float(ext:gross.replace(',', ''))
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Instrumented code behaves exactly like the original. `exec_source` executes the code it is given: only use it on code you would run anyway.
|
|
255
|
+
|
|
256
|
+
### Saving, inspecting and viewing traces
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
data = trace.to_json() # versioned format; store it with the run
|
|
260
|
+
restored = rr.Trace.from_json(data)
|
|
261
|
+
print(restored.propagate({"ext:gross": "6,000"}).outputs["out:net"].new) # 4800.0
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
redroot explain trace.json out:summary.net # expression and source inputs
|
|
266
|
+
redroot coverage trace.json # coverage report + re-evaluation check
|
|
267
|
+
redroot visualize trace.json # web viewer (needs redroot[web])
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
To re-evaluate a loaded trace, the modules defining its `@traced` functions must be imported, since they register those operations.
|
|
271
|
+
|
|
272
|
+
### Measuring whether tracing covers your workload
|
|
273
|
+
|
|
274
|
+
Before relying on propagation, measure it on real runs:
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from redroot.validation import check_identity, check_perturbation, coverage
|
|
278
|
+
|
|
279
|
+
# Linked and replayable outputs, guards, and the inputs that feed guards:
|
|
280
|
+
print(coverage(trace))
|
|
281
|
+
assert check_identity(trace).ok # every node re-evaluates to its recorded value
|
|
282
|
+
report = check_perturbation(guarded, {"A": 1200, "B": 300}, {"ext:A": 1100}, input_root="ext")
|
|
283
|
+
assert report.consistent # graph agrees with re-execution wherever it claimed to know
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Pydantic
|
|
287
|
+
|
|
288
|
+
With `redroot[pydantic]`, traced types work as model fields. Traced values pass through validation with their lineage, plain values become inputs, and models serialize to plain values.
|
|
289
|
+
|
|
290
|
+
## How it works
|
|
291
|
+
|
|
292
|
+
Traced types subclass the builtins and override their operators. Each operation computes its result with the same function the graph later uses to re-evaluate it, so recomputation reproduces execution exactly. Results that leave tracking (a `bool` from a comparison, an `int()` conversion, a hash) are recorded as *guards*. Propagation re-checks guards, and any change means execution could have diverged. Details, guarantees and limits are in [docs/design.md](docs/design.md). For an end-to-end review workflow (record, review, edit, verify), see [docs/integration.md](docs/integration.md).
|
|
293
|
+
|
|
294
|
+
Overhead is about 0.7 µs per traced operation (0.9 µs for `Decimal`) and about 240 bytes per recorded node (`python benchmarks/overhead.py`).
|
|
295
|
+
|
|
296
|
+
## Limitations
|
|
297
|
+
|
|
298
|
+
- Only `int`, `float`, `Decimal` and `str` are traced. `bool` and `None` inputs are recorded as untracked: editing them requires re-execution.
|
|
299
|
+
- Without instrumentation, a few C-level operations lose lineage (see above). `redroot.validation` finds them. [docs/design.md](docs/design.md#what-remains-invisible) lists what remains invisible even with it.
|
|
300
|
+
- Lineage does not cross threads unless the context is propagated (`contextvars.copy_context()`), nor processes, nor `pickle`.
|
|
301
|
+
- `type(x) is float` is `False` for traced values (instrumented code is unaffected).
|
|
302
|
+
|
|
303
|
+
## Contributing
|
|
304
|
+
|
|
305
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md), and [AGENTS.md](AGENTS.md) for the architecture's invariants.
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
MIT. See [LICENSE](LICENSE).
|