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 )
- paths are POSIX style, so a Windows run and a Linux run agree
- the path is hashed too, so a rename is a change
- NUL separators mean the concatenation is unambiguous
- symlinks are skipped unless
follow_symlinks=True, so a link to a large tree does
not silently change the digest
- mtimes, permissions and owners are not used at all
Ignore rules
.gitignore in the root is read by default (gitignore=False turns it off), and patterns= accepts the same syntax:
| pattern | matches |
|---|---|
*.pyc | any depth |
docs/*.md | a path, from the root |
docs/**/a.md | any depth under docs |
build/ | a directory only |
/top.log | anchored to the root |
!keep.log | un-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
- No hard links, submodules or file modes: content and names only.
- A
.gitignoreinside a subdirectory is not read; passpatterns=for those. - Reading is single threaded and chunked at 1 MiB, which is fast enough for source
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.
- argrepair — turn a bad tool call into a message the model can act on
- backoff-headers — turn a rate-limit header into the exact time to wait
- columncheck — find the CSV defect before the pipeline does
- docanchor — catch every broken heading anchor in your docs
- envfile-diff — diff two .env files without printing the secrets
- fsync-replace — replace a file so a crash cannot leave it half-written
- header-date — HTTP dates parsed strictly, formatted correctly
- junit-merge — merge JUnit XML from every job into one honest report
- npm-semver — npm semver ranges, parsed the way npm parses them
- outputcap — keep a huge tool result out of the context window
- parse-size — byte sizes in and out, MB and MiB never confused
- path-containment — keep untrusted paths inside their directory
- redactscope — stop secrets in tool results before they reach the model
- runbudget — a per-run cost cap that warns before it stops
- testflakes — rank your flaky tests from the history you already have
- tool-loop-guard — catch an agent repeating itself while it is still cheap
- toolcall-ledger — a hash-chained record of every tool call
- toolcircuit — stop retrying a tool that is down
- toolquota — client-side rate limits your agent loop can wait on
- wheeldeps — read a wheel's dependencies offline, markers included
- zip-deterministic — byte-identical archives, build after build