dupefind
Find duplicate files by staged hashing: group by size, then partial hash, then full hash.
A small, fully typed library with no dependencies (standard hashlib only) and a
command line tool. Scanning only reads files. Clean-up is a separate, explicit step
that is a dry run unless you say otherwise.
Install
pip install dupefind
Quick start
from dupefind import scan
report = scan("photos/import", "photos/library")
for group in report.groups:
print(group.size, group.digest)
for path in group.paths:
print(" ", path)
for issue in report.issues: # unreadable, vanished or changed while reading
print("skipped", issue.path, issue.kind)
The original interface still works and returns dict[str, list[Path]] keyed by
the SHA-256 of the content:
from dupefind import find_duplicates, iter_duplicates
groups = find_duplicates("path/to/tree")
for digest, paths in iter_duplicates("path/to/tree"):
...
Options
from dupefind import ScanOptions, iter_groups
options = ScanOptions(
algorithm="blake2b", # any fixed-size hashlib algorithm, default sha256
partial_size=64 * 1024, # bytes hashed before any full read
min_size=1, # leave empty files alone
exclude=(".git", "*.tmp"),
)
for group in iter_groups("data", options=options, on_progress=print):
...
Safe defaults, in line with fdupes, jdupes and rmlint:
- Hard links are one file. Several names of the same file are merged and kept
in
aliases; a set made only of hard links is never a duplicate group. Sethardlinks=Trueto list every name. - Links are not followed. Symlinks and Windows junctions found while walking
are skipped unless
follow_symlinks=True. Paths you pass in are always used. - A file is never its own duplicate. Overlapping roots, a root given twice, a root in another letter case, or a link loop never list one file twice.
- Changes are caught. A file whose size or modification time changes while it is read is left out and reported.
- Errors are reported, not raised. Permission errors and vanished files become
ScanIssueentries.
Cleaning up
from dupefind import apply_actions, plan_actions, scan
plan = plan_actions(scan("photos").groups, action="delete", keep="oldest")
for result in apply_actions(plan): # dry run: nothing changes
print(result.status, result.planned.target)
apply_actions(plan, dry_run=False) # now it happens
keep is first, oldest, newest or shortest. action="hardlink" replaces
each copy with a hard link to the kept file instead. Right before acting, every
pair is checked again: both files exist, are not the same file, have the scanned
size, and are equal byte for byte; then both are stat'ed once more just before the
act, the target is moved aside and checked again, and the kept file is held open.
Links, junctions, read-only files and (on Windows) files with extra data streams
are never removed or replaced. Anything else is skipped and reported.
Command line
dupefind ~/Pictures # list duplicate groups
dupefind a b --min-size 1M --json # two trees, JSON report
dupefind . --exclude .git --exclude "*.tmp"
dupefind . --delete --keep oldest # show the plan (dry run)
dupefind . --delete --keep oldest --apply # really delete the other copies
dupefind . --hardlink --apply # link copies to one file
Nothing changes unless --apply is given with --delete or --hardlink. Those
two leave empty files alone unless --empty is added. A summary and any skipped paths go to stderr. Exit status is 0 on success and 1 on
an error or a failed action.
See GUIDE.md for the staging, every option, the JSON schema and the safety checks in detail.
Why
Finding duplicate files is a common chore, but the Python packages for it are
mostly stale: fastdupes last shipped in 2015, dupfinder in 2010, and dupe in
2021. The few that are maintained are command-line tools, not a typed library you
can import. dupefind is both: a typed API with safe link handling and explicit,
verified clean-up, and a CLI for the shell.
License
MIT. See LICENSE.
Links
- Website: https://lianes8studio.com
- GitHub: https://github.com/JaviLianes8
- LinkedIn: https://www.linkedin.com/in/jlianes/
Metadata
Release files for dupefind 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dupefind-0.2.0.tar.gz | 39.9 kB | Without provenance | Details for dupefind-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dupefind-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for dupefind-0.2.0-py3-none-any.whl |
Total release size: 65.4 kB
Release files / dupefind-0.2.0.tar.gz
| Download URL | dupefind-0.2.0.tar.gz |
|---|---|
| Size | 39.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bb8545a90434641282e05d198d558716dc7edf53bc6bcbbbb4b3edc5a5fe508
|
|
BLAKE2b-256 checksum How to use checksums |
373bc29cdeb8d13a56067927aa770c970997c6d85bbee900c2f3f531f22ad78f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / dupefind-0.2.0-py3-none-any.whl
| Download URL | dupefind-0.2.0-py3-none-any.whl |
|---|---|
| Size | 25.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
45a05d9f29f4c5f92d72c34e48f95dc040aa86f49423be02dd6de9ed136f9531
|
|
BLAKE2b-256 checksum How to use checksums |
6b1ffef584aa246912258141f1e518d6faf934a57920ad6a78713f5e37cc39c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for dupefind 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.