dir-digest
dir-digest

how dir-digest fits in

Install

consolepip install dir-digest

Use

pythonfrom dir_digest import digest_tree, file_digests

digest_tree("src")                                   # one hex digest
digest_tree("src", algorithm="sha1", patterns=["*.pyc"])
file_digests("src")                                  # {"a.py": "…", "pkg/b.py": "…"}
consoledir-digest DIR [--algorithm sha256] [--ignore PATTERN]… [--no-gitignore] [--files] [--json]

How the digest is built

hash( for each file, sorted by relative path:
        relative_path + NUL + hash_of_contents + NUL )

not silently change the digest

Ignore rules

.gitignore in the root is read by default (gitignore=False turns it off), and patterns= accepts the same syntax:

pattern matches
*.pycany depth
docs/*.mda path, from the root
docs/**/a.mdany depth under docs
build/a directory only
/top.loganchored to the root
!keep.logun-ignores; the last matching rule wins

This is the subset of gitignore people actually write — comments, negation, *, ?, **, character classes, trailing-slash directories and leading-slash anchoring.

Limits

trees but not a substitute for a specialised filesystem scanner.

Development

consolepython -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/pytest

The suite covers every line of the package (pytest --cov --cov-branch), and the examples in the docstrings run as tests through --doctest-modules.

License

MIT.

Other libraries here

One problem each, standard library only, no runtime dependencies.