Filesystem state snapshots with diff comparison
Project description
philiprehberger-dir-snapshot
Filesystem state snapshots with diff comparison.
Installation
pip install philiprehberger-dir-snapshot
Usage
Take a Snapshot
from philiprehberger_dir_snapshot import snapshot
snap = snapshot("./src")
print(f"Found {len(snap.files)} files")
Compare Snapshots
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 and Load
# Save to JSON
before.to_json("snapshot.json")
# Load later
from philiprehberger_dir_snapshot import Snapshot
restored = Snapshot.from_json("snapshot.json")
Options
# 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")
Verify a Snapshot
Re-check that every file recorded in a snapshot is still on disk and unchanged — useful for backup verification or detecting silent corruption.
snap = snapshot("./backup", hash_mode="sha256")
# ... time passes / backup is restored ...
report = snap.verify()
if report.is_intact:
print("backup intact")
else:
print(report.summary())
for path in report.missing:
print(f"missing: {path}")
for path in report.modified:
print(f"corrupt: {path}")
API
| 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.verify(strict=False) |
Re-check stored entries against disk; returns VerifyReport |
Snapshot.to_json(path) / Snapshot.from_json(path) |
Serialize/deserialize |
VerifyReport.is_intact |
True when nothing is missing or modified |
VerifyReport.verified / .missing / .modified |
File path lists |
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 |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Project details
Release history Release notifications | RSS feed
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 philiprehberger_dir_snapshot-0.3.0.tar.gz.
File metadata
- Download URL: philiprehberger_dir_snapshot-0.3.0.tar.gz
- Upload date:
- Size: 179.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25c298aa9a5a8eb43087840c15b5f1a1b7466cc4337e7ea053a6cbc977260aa9
|
|
| MD5 |
fe76fbc1499a4bfc4a79455b2ad8fe2b
|
|
| BLAKE2b-256 |
6d2eb6a24b8eb926e3bb818598c5228a86f1f0e35914b53bdd8c98e497b7d58b
|
File details
Details for the file philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab0631087057f84eded523c4b6b976dc058dde5a5cbcc4b619c3d4ec7bbb2ed6
|
|
| MD5 |
931b43eae7a3cad2fb695f1127f6d637
|
|
| BLAKE2b-256 |
be3a07a1583e252e8d1044ed244de991806c9e017fe48ec997f16327b663b914
|