📦 Treestamps
Fast, persistent timestamps for recursive filesystem operations.
Treestamps lets you skip work you’ve already done.
If your program walks directory trees and processes files (optimization, transcoding, validation, etc.), Treestamps tracks what you've already handled—so subsequent runs are incremental, not repetitive.
🚀 Why Treestamps?
Treestamps gives you:
- Persistent state across runs
- O(1) “have I seen this file before?” checks
- Automatic invalidation when config changes
- No database dependency (just YAML files)
- Safe writes via WAL (write-ahead log)
- Quiet by default — your program owns user-facing output
🧠 Mental model
Treestamps is built around three concepts:
1. Grove
A Grovestamps instance manages timestamps across multiple root paths.
2. Tree
Each configured path (e.g. /photos) is a tree.
3. Stamp
Each file gets a timestamp keyed by its relative path within the tree.
Examples
Full use
from pathlib import Path
from treestamps import Grovestamps, GrovestampsConfig
config = GrovestampsConfig(
"MyProgram", paths=("/data/photos", "/data/videos"), program_config={"quality": 90}
)
gs = Grovestamps(config)
ts = gs[Path("/data/photos")]
if ts.get("img001.jpg") is None:
process("img001.jpg")
ts.set("img001.jpg")
gs.dumpf()
Skip unchanged files
for file in files:
if ts.get(file) is not None:
continue # already processed
process(file)
ts.set(file)
Invalidate when config changes
GrovestampsConfig("MyProgram", paths=("/data",), program_config={"quality": 80})
If you later change:
program_config = {"quality": 90}
👉 All timestamps are invalidated automatically.
Multi-root trees
config = GrovestampsConfig(
"MyProgram",
paths=("/a", "/b"),
)
Each root gets its own timestamp file, but shares config logic.
⚙️ How it works
Treestamps uses two files per root directory:
1. WAL file (write-ahead log)
.MyProgram_treestamps.wal.yaml
- Appended during runtime
- Fast writes
- Crash-safe
2. Final snapshot
.MyProgram_treestamps.yaml
- Written on
dump() - Compact
- Used on next startup
Lifecycle
- Load
.yaml(if exists) - Replay
.wal.yaml(if exists) - Serve reads/writes in memory
- Append writes to WAL
- On
dumpf():- Merge everything
- Write
.yaml - Delete WAL
💾 When to call dumpf()
dumpf() commits the in memory treestamps data to disk.
Call it when
- At the end of a successful run
- After processing a large batch
- Before shutdown in long-running processes
Don’t call it
- After every file (too slow)
- If the run failed (you may want to discard progress)
🤫 Output and progress
Treestamps does not print progress, status, or success messages. Reporting what's happening to your users is your program's job.
The only output Treestamps emits is a handful of error messages from loadf(),
loads(), and the WAL load path when YAML or timestamp entries can't be parsed.
Set verbose=0 on your config to suppress those too.
Reporting from return values
Treestamps.loadf(), Treestamps.loads(), and Treestamps.dumpf() return a
bool so you can drive your own logging or progress UI:
loadf()/loads()—Trueon a successful loaddumpf()—Trueif a write to disk actually happened,Falseif there was nothing new to commit (noset()since the last dump and no consumed child timestamp files)
if ts.dumpf():
print(f"Saved timestamps for {top_path}")
🧨 Error handling
Treestamps is designed to be robust but not magical.
Corrupt YAML
If .yaml is unreadable or treated as missing the WAL may still recover recent
writes
WAL corruption
- Partial WAL entries may be ignored
- Worst case: last few writes lost (not the entire dataset)
Config mismatch
- If a recorded
program_configvalue changes:- Old timestamps are ignored
- No partial reuse
- Adding or retiring a recorded key is not a change by itself: with
program_config_defaultsset, keys missing from either side are filled from the defaults before comparing
Missing files
- If a file disappears:
- Its stamp remains
- It is your responsibility to handle filesystem drift
🧩 Configuration (GrovestampsConfig)
Construct configs with keyword arguments: fields are added between releases, which shifts positional order.
GrovestampsConfig(
program_name: str,
paths: Iterable[str | Path],
program_config: dict = None,
program_config_keys: Iterable[str] = frozenset(),
program_config_defaults: dict = None,
program_config_key_labels: Mapping[str, str] = {},
note: Iterable[str] = (),
tree_config_factory: Callable[[Path], TreestampsConfig | None] = None,
verbose: int = 0,
)
Fields
program_name
-
Used in filenames:
. < program_name > _treestamps.yaml
paths
- Root directories to manage
- Each gets its own stamp file
program_config
- Arbitrary dict
- Recorded in the stamp file and compared on load
- Changing a recorded value invalidates that tree's timestamps
Record every option your file selection depends on, including the treestamps
ignore and symlinks options if they affect it: treestamps does not record
them itself.
program_config_keys
- The keys of
program_configthat are actually recorded - Everything else is filtered out before serialization
program_config_defaults
- Your program's default values for the recorded keys
- Missing keys are filled from it on both sides before comparing, so adding or retiring a recorded key does not invalidate stamp files written before the change — only keys whose values really differ do
- Not filtered by
program_config_keys: keep a retired key's last default here so old files that recorded it at its default still compare as matching - New keys must default to behavior-preserving values, because a key missing from an old file is read as "the current default"
program_config_key_labels
- Maps internal key names to human readable names in mismatch warnings
- Useful for synthetic keys like a config-file fingerprint
note
- Extra comment lines for the generated file header
- Line breaks are rejected: a note line must stay one comment line
tree_config_factory
- Called once per top path to build that tree's
TreestampsConfig - Use it when each tree records a different resolved program config, which one
shared
program_configcannot express - Return
Noneto skip a tree entirely: no store, no stamp file
verbose
- Retained for compatibility; no longer gates output
- Load and WAL errors are reported as warnings through the
treestampslogger — configure visibility with the standardloggingmodule
🔑 Per-directory config fingerprints
A single recorded program_config cannot see per-directory config files below
the tree root. dir_config_fingerprint() hashes their option values into one
key you fold into the program config:
from treestamps import dir_config_fingerprint
program_config["_dir_config_fingerprint"] = dir_config_fingerprint(
root_dir, ".myprogram.yaml", "myprogram"
)
Comment, whitespace, and key-order edits do not change the digest; option value
edits, adds, removes, and renames do. exclude_root=True (the default) skips
the root's own config file, which is correct when the root's resolved options
are already recorded as values. Pair it with program_config_key_labels so
mismatch warnings name something a user recognizes.
🧾 YAML file format
Snapshot file
# @generated by treestamps 5.0.0 for myprogram — machine-written; do not edit.
# Not a config file: the `config:` block is a snapshot of the
# resolved options that produced these timestamps; it is compared,
# never applied.
config:
quality: 90
img001.jpg: 1700000000.123
img002.jpg: 1700000001.456
The config key holds the program config (the keys selected by
program_config_keys). If it mismatches the running config, the file's
timestamps are discarded (unless check_config=False). All remaining keys are
path-to-mtime timestamp entries.
Files written before 5.0.0 also carry a treestamps_config block recording
ignore and symlinks. It is no longer written or compared, but it is still
popped when loading, so old files load normally.
WAL file
The WAL starts with the same header, followed by a wal list that gets one
appended entry per set():
# @generated by treestamps 5.0.0 for myprogram — machine-written; do not edit.
# Not a config file: the `config:` block is a snapshot of the
# resolved options that produced these timestamps; it is compared,
# never applied.
config:
quality: 90
wal:
- img003.jpg: 1700000002.789
- img004.jpg: 1700000003.0
Notes
- Paths are relative to root
- Timestamps are typically float seconds
- WAL is append-only
🧪 Real-world use cases
🖼️ Image optimization (picopt)
In picopt:
- Avoid re-optimizing unchanged images
- Skip entire archives if contents are unchanged
- Handle millions of files efficiently
- Handle config changes (e.g. compression settings) by invalidating stamps ([New Releases][1])
🎬 Media cleanup (nudebomb)
In nudebomb:
- Avoid reprocessing already-cleaned MKVs
- Track work across large media libraries
- Resume interrupted runs safely
🧰 General pattern
Treestamps is ideal for anything that
- walks a tree
- does expensive work
- runs repeatedly
🛠️ Troubleshooting
“Everything is reprocessing every run”
- Did
program_configchange? - Did
program_namechange? - Are you calling
dumpf()?
“Timestamps not persisting”
- Ensure
dumpf()is called (and check its return value —Falsemeans nothing was written) - Check write permissions in root directories
“Unexpected invalidation”
- Any change in
program_configinvalidates all stamps - Even ordering or defaults may matter
“WAL file keeps growing”
- You’re not calling
dumpf() - WAL is expected to grow until committed
“Files moved or renamed”
- Treestamps uses relative paths
- Renames = treated as new files
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file treestamps-5.0.1.tar.gz.
File metadata
- Download URL: treestamps-5.0.1.tar.gz
- Upload date:
- Size: 225.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89f06f285163abe40fa318367a6f98ffa147198719fa7e8b1dd776a58f89ba20
|
|
| MD5 |
f097bc8283688810044143993699738c
|
|
| BLAKE2b-256 |
78dc9415b1376bca84fb89162202a2a7cbaaf9dbff5025c93a8ddfb5ecadea92
|
File details
Details for the file treestamps-5.0.1-py3-none-any.whl.
File metadata
- Download URL: treestamps-5.0.1-py3-none-any.whl
- Upload date:
- Size: 37.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
596732cc314036d7cf9d25eca42b315b28e8fa65176ba5df1aacfa66de3fd074
|
|
| MD5 |
c5c45e7bd714c32b946a2f66af8d5d50
|
|
| BLAKE2b-256 |
30ef466124caf10c07606ce54dba8bdddea20f402747c9c9e613a70e1c5a1b5d
|