Filesystem state snapshots with diff comparison
pip install philiprehberger-dir-snapshotFilesystem state snapshots with diff comparison.
pip install philiprehberger-dir-snapshot
from philiprehberger_dir_snapshot import snapshot
snap = snapshot("./src")
print(f"Found {len(snap.files)} files")
before = snapshot("./src")
# ... make changes ...
after = snapshot("./src")
diff = before.diff(after)
print(diff.summary())
for f in diff.added:
print(f"+ {f.path}")
for f in diff.removed:
print(f"- {f.path}")
for f in diff.modified:
print(f"~ {f.path}")
# Save to JSON
before.to_json("snapshot.json")
# Load later
from philiprehberger_dir_snapshot import Snapshot
restored = Snapshot.from_json("snapshot.json")
# Include only Python files
snap = snapshot("./src", include=["*.py"])
# Exclude build artifacts
snap = snapshot(".", exclude=["__pycache__", "*.pyc", ".git"])
# Use faster hashing (or disable with "none")
snap = snapshot(".", hash_mode="md5")
| Function / Class | Description |
|---|---|
snapshot(path, hash_mode="mtime", include=None, exclude=None) | Create a directory snapshot |
Snapshot.diff(other) | Compare two snapshots, returns SnapshotDiff |
Snapshot.to_json(path) / Snapshot.from_json(path) | Serialize/deserialize |
FileEntry | File metadata — .path, .size, .mtime, .hash |
SnapshotDiff.has_changes | True if any files were added, removed, or modified |
SnapshotDiff.added / .removed / .modified / .unchanged | Lists of file paths |
SnapshotDiff.summary() | Human-readable diff summary |
pip install -e .
python -m pytest tests/ -v
If you find this project useful: