A lightweight, modular Python tool to:
- Recursively scan folders
- Compute SHA-256 hashes for all files
- Detect exact duplicates by content
- Provide a clean API for developers
Zero dependencies. Easy to integrate.
- Recursive folder scanning
- Secure SHA-256 hashing (64KB chunks)
- Duplicate detection by file content
- Clean, object-oriented API
- Ready-to-use example script
- No external packages required
git clone https://github.com/dillionhuston/SHA-256-File-Hasher.git
cd SHA-256-File-Hasher-
No requirements.txt needed — pure Python!
sha256-duplicate-finder
│
├── API/
│ ├── __init__.py
│ ├── API.py # Main API entry point
│ ├── HashFile.py # SHA-256 file hasher
│ ├── ScanFolder.py # Recursive folder scanner
│ ├── FolderHandler.py # Hash all files in folder
│ └── DuplicateFinder.py # Detect duplicate groups
│
├── usage.py # Example usage
└── README.mdfrom API.API import FileHasherAPI
# Initialize with folder path
api = FileHasherAPI("path/to/your/folder")
# Get all file hashes
hashes = api.get_hashes()
# → { "file1.txt": "a1b2c3...", "file2.txt": "a1b2c3..." }
# Get only duplicates
duplicates = api.get_duplicates()
# → { "a1b2c3...": ["file1.txt", "copy/file1.txt"] }All file hashes:
text/file1.txt: d179aeebdc32f0d8a2...
text/file2.txt: d179aeebdc32f0d8a2...
text/unique.txt: 8bc74a21e3f14c9d...
Duplicates found:
Hash: d179aeebdc32f0d8a2...
- text/file1.txt
- text/file2.txt
python usage.py-
ScanFolder.scan_folder(folder_path)- Uses
os.walk()to recursively traverse the directory. - Collects absolute paths of all files (ignores directories).
- Returns a flat list of file paths.
- Uses
-
HashFile.hash_file()- Opens file in binary mode (
'rb'). - Reads in 64KB chunks to support large files efficiently.
- Updates
hashlib.sha256()hasher incrementally. - Returns hex digest (64-character string).
- Opens file in binary mode (
-
FolderHandler.hash_folder()- Scans folder → gets file list.
- For each file:
- Instantiates
HashHandler(file_path) - Computes hash
- Builds a reverse map:
{hash: [file_path, ...]}
- Instantiates
- Prints progress (optional)
- Returns the full hash map
-
DuplicateFinder.find_duplicates(hash_dict)- Iterates over the hash map.
- Filters groups where
len(files) > 1. - Returns only duplicate groups
- Prints human-readable summary
-
FileHasherAPI- Public interface
get_hashes()→ returns full{file: hash}mapget_duplicates()→ returns only duplicate groups- No side effects beyond optional prints
Thread-safe? No — uses standard file I/O.
Memory usage? Stores all file paths and hashes in memory.
Large files? Yes — streams in 64KB chunks.
Zero dependencies — purestdlib.
- Clean up duplicate photos, documents, or backups
- Audit datasets for redundancy
- Integrate into backup/sync tools
- Pre-process data for ML pipelines
- Fork the repo
- Create a branch:
git checkout -b feature/your-feature - Commit:
git commit -m "Add your feature" - Push & open a Pull Request
MIT License – Free to use, modify, and distribute.
Dillon Huston
GitHub Profile
Small. Fast. Reliable.
Find duplicates. Save space. Code smarter.