Checksumdir is a Python library designed to compute a single cryptographic hash for the contents of a given directory. It primarily focuses on the file contents, ignoring metadata by default. The current version is 1.3.0 and it maintains a sporadic or infrequent release cadence, with the latest PyPI release dated August 15, 2025.
pip install checksumdirVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to compute MD5 and SHA1 hashes for a directory. It shows the default behavior of hashing only file contents and how to include filenames in the hash calculation. It also includes an example of excluding files by extension. The example uses a temporary directory for a self-contained demonstration.
To include filenames or file paths in the hash calculation, use the `hash_filename=True` or `hash_filepath=True` arguments, introduced in version 1.2.0.
Ensure the directory exists before attempting to hash it, e.g., by checking `os.path.isdir(directory_path)`.
For extremely large datasets, consider hashing only critical subsets, or implement caching mechanisms for hashes that change infrequently. The `dirhash` library (a similar tool) supports multiprocessing for speedup if applicable.
Upgrade your Python interpreter to version 3.9 or newer, or pin `checksumdir` to a compatible earlier version (e.g., `pip install 'checksumdir<1.3.0'`).
Ensure the target directory exists before calling `checksumdir.dirhash()`, e.g., by checking `os.path.isdir(directory_path)` or creating it if intended.
Install the library using pip: `pip install checksumdir`. If packaging with tools like PyInstaller, ensure the module is properly bundled.
Grant the user running the script appropriate read permissions for the target directory and its contents. On Windows, ensure no other applications are holding locks on the files.
For extremely large datasets, consider hashing only critical subsets, implement caching for unchanging hashes, or explore external tools that support multiprocessing for directory hashing.
To include filenames or file paths in the hash calculation, use the `hash_filename=True` or `hash_filepath=True` arguments in the `dirhash` function.