pytracked
Reactive memoization with dependency-driven invalidation for Python.
Like functools.cache, but with automatic invalidation: when an input changes,
all computed values that depend on it are flushed and lazily recomputed on next access.
Features
tracked— memoized attribute with automatic dependency recordingtoken— mutable input; writing a new value flushes all dependents transitivelycircular— fixed-point iteration for mutually recursive computationsflush— manually invalidate cached valuesobserve— trace evaluation order and profile cache efficiency
Quick start
from pytracked import tracked, token
class Spreadsheet:
a = token(1)
b = token(2)
total = tracked(lambda self: self.a + self.b)
label = tracked(lambda self: f"Total: {self.total}")
s = Spreadsheet()
s.total # → 3 (computed, cached)
s.total # → 3 (cache hit)
s.a = 10 # flushes total and label transitively
s.total # → 12 (recomputed)
s.label # → "Total: 12" (recomputed)
Fixed-point computation
from pytracked import tracked, circular
class Grammar:
# Compute nullable set iteratively until stable
nullable = circular(lambda self: self._compute_nullable(), bottom=frozenset)
def _compute_nullable(self):
result = set()
for rule in self.rules:
if all(sym in self.nullable for sym in rule.rhs):
result.add(rule.lhs)
return frozenset(result)
How it works
During evaluation of a tracked attribute, any access to another tracked or
token attribute is recorded as a dependency edge. When a token is written,
the dependency graph is walked transitively to flush all stale cached values.
Re-evaluation happens lazily on next access.
This implements the algorithm from:
Söderberg & Hedin, "Incremental Evaluation of Reference Attribute Grammars using Dynamic Dependency Tracking", LU-CS-TR:2012-249.
Metadata
Release files for pytracked 0.1.2
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 |
|---|---|---|---|---|
| pytracked-0.1.2.tar.gz | 12.1 kB | Without provenance | Details for pytracked-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytracked-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for pytracked-0.1.2-py3-none-any.whl |
Total release size: 24.0 kB
Release files / pytracked-0.1.2.tar.gz
| Download URL | pytracked-0.1.2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76143adb60d520cd12a0c102ea5846fae165eb7b721887953f38ee1bb3e29497
|
|
BLAKE2b-256 checksum How to use checksums |
4e0b4b46b36c47d08b8922e37666ef4ad3353de2b8aa1454bc93c50b05dad374
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / pytracked-0.1.2-py3-none-any.whl
| Download URL | pytracked-0.1.2-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0215020132b7cbde8852ac6270c97f6d32bc79ab82d372ea863c3b5cf1e714d
|
|
BLAKE2b-256 checksum How to use checksums |
24b3463e377bb4fff1fd50c1dd72f5e2d045896b19c042c8755811f1ccfb4e8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Security for pytracked 0.1.2
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.