dirhash is a Python module and CLI tool for computing the hash of file system directories based on their structure and content. It supports all hashing algorithms available in Python's `hashlib` module, offers `.gitignore`-style glob/wildcard path matching for filtering files, and leverages multiprocessing for performance. The library computes hashes according to the Dirhash Standard, aiming for consistent and collision-resistant directory hash generation. It is actively maintained with irregular, feature-driven releases, currently at version 0.5.0.
pip install dirhashVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to compute directory hashes using different algorithms and filtering options (`match` and `ignore` for `.gitignore` style patterns) using the `dirhash` function. It also shows the effect of including empty directories.
Review and test any existing directory hashing logic, especially those relying on `match` or `ignore` patterns, to ensure the new `.gitignore`-aligned behavior is as expected.
Users migrating from `v0.1.x` versions must thoroughly review the API and expected hash outputs against the new 'Dirhash Standard' implementation in `v0.2.0` and later.
Ensure your project is running on Python 3.8 or a newer compatible version.
Report any Windows-specific issues to the project's GitHub repository. Consider thorough testing on Windows environments before using in production.
Carefully configure `empty_dirs`, `no_linked_dirs`, `no_linked_files`, `allow_cyclic_links`, and `properties` arguments to precisely define what should be included in the hash, especially in environments with complex file structures or symbolic links. Refer to the 'Dirhash Standard' documentation for detailed behavior.
pip install dirhash
dirhash /path/to/directory
Use a valid hashing algorithm from Python's hashlib, such as 'md5', 'sha1', 'sha256', 'sha512', etc.
Example: dirhash('/path/to/directory', 'sha256')Ensure the user running `dirhash` has read permissions for all files and directories within the target path, or use the `ignore` argument (e.g., `--ignore 'path/to/inaccessible_dir/*'` in CLI or `ignore=['path/to/inaccessible_dir/*']` in Python) to exclude the inaccessible paths.
Always enclose glob/wildcard patterns in quotes when using them with `dirhash` on the command line. Example: dirhash path/to/directory --match "*.py"