Skip to main content

Filesystem state snapshots with diff comparison

Project description

philiprehberger-dir-snapshot

Tests PyPI version Last updated

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:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_dir_snapshot-0.3.0.tar.gz (179.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_dir_snapshot-0.3.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_dir_snapshot-0.3.0.tar.gz
Algorithm Hash digest
SHA256 25c298aa9a5a8eb43087840c15b5f1a1b7466cc4337e7ea053a6cbc977260aa9
MD5 fe76fbc1499a4bfc4a79455b2ad8fe2b
BLAKE2b-256 6d2eb6a24b8eb926e3bb818598c5228a86f1f0e35914b53bdd8c98e497b7d58b

See more details on using hashes here.

File details

Details for the file philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab0631087057f84eded523c4b6b976dc058dde5a5cbcc4b619c3d4ec7bbb2ed6
MD5 931b43eae7a3cad2fb695f1127f6d637
BLAKE2b-256 be3a07a1583e252e8d1044ed244de991806c9e017fe48ec997f16327b663b914

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page