Skip to main content

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

Release files for philiprehberger-dir-snapshot 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for philiprehberger-dir-snapshot 0.3.0
File Size Uploaded
philiprehberger_dir_snapshot-0.3.0.tar.gz 179.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for philiprehberger-dir-snapshot 0.3.0
File Interpreter ABI Platform
philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 185.5 kB

Release files / philiprehberger_dir_snapshot-0.3.0.tar.gz

Download URL philiprehberger_dir_snapshot-0.3.0.tar.gz
Size 179.0 kB
Tags Source
SHA-256 checksum
How to use checksums
25c298aa9a5a8eb43087840c15b5f1a1b7466cc4337e7ea053a6cbc977260aa9
BLAKE2b-256 checksum
How to use checksums
6d2eb6a24b8eb926e3bb818598c5228a86f1f0e35914b53bdd8c98e497b7d58b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl

Download URL philiprehberger_dir_snapshot-0.3.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab0631087057f84eded523c4b6b976dc058dde5a5cbcc4b619c3d4ec7bbb2ed6
BLAKE2b-256 checksum
How to use checksums
be3a07a1583e252e8d1044ed244de991806c9e017fe48ec997f16327b663b914
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page