Python module and CLI for hashing of file system directories.
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install dirhashdirhash
A lightweight python module and CLI for computing the hash of any directory based on its files' structure and content.
- Supports all hashing algorithms of Python's built-in
hashlibmodule. - Glob/wildcard (".gitignore style") path matching for expressive filtering of files to include/exclude.
- Multiprocessing for up to 6x speed-up
The hash is computed according to the Dirhash Standard, which is designed to allow for consistent and collision resistant generation/verification of directory hashes across implementations.
Installation
From PyPI:
pip install dirhash
Or directly from source:
git clone git@github.com:andhus/dirhash-python.git
pip install dirhash/
Usage
Python module:
from dirhash import dirhash
dirpath = "path/to/directory"
dir_md5 = dirhash(dirpath, "md5")
pyfiles_md5 = dirhash(dirpath, "md5", match=["*.py"])
no_hidden_sha1 = dirhash(dirpath, "sha1", ignore=[".*", ".*/"])
CLI:
dirhash path/to/directory -a md5
dirhash path/to/directory -a md5 --match "*.py"
dirhash path/to/directory -a sha1 --ignore ".*" ".*/"
Why?
If you (or your application) need to verify the integrity of a set of files as well as their name and location, you might find this useful. Use-cases range from verification of your image classification dataset (before spending GPU-$$$ on training your fancy Deep Learning model) to validation of generated files in regression-testing.
There isn't really a standard way of doing this. There are plenty of recipes out
there (see e.g. these SO-questions for linux
and python)
but I couldn't find one that is properly tested (there are some gotcha:s to cover!)
and documented with a compelling user interface. dirhash was created with this as
the goal.
is another python module/tool with similar intent (that inspired this project) but it lacks much of the functionality offered here (most notably including file names/structure in the hash) and lacks tests.