Lightweight file management utilities for deduplication and organization
Project description
fileherder
Lightweight File Management Utilities
A focused Python package for essential file management operations without heavy dependencies.
Features
- Duplicate Detection - Hash-based duplicate finding with SHA256
- File Organization - Automatic categorization by file type
- Batch Operations - Safe move, copy, delete, and rename operations
- Type Detection - Smart file type classification
- Rich CLI - Beautiful terminal interface (optional)
- Zero Required Dependencies - Core functionality works standalone
Installation
# Basic installation (no dependencies)
pip install fileherder
# With Rich CLI (recommended)
pip install fileherder[cli]
# Development install
pip install fileherder[dev]
Quick Start
Command Line
# Find duplicate files
fileherder duplicates /path/to/directory
# Find duplicate images larger than 1MB
fileherder duplicates /photos --min-size 1048576 --extensions .jpg,.png
# Organize directory by file type
fileherder organize /downloads
# Show directory statistics
fileherder stats /data
Python API
from fileherder import FileHerder
# Create herder instance
herder = FileHerder()
# Find duplicates
duplicates = herder.find_duplicates(
Path("/data"),
min_size=1024*1024, # Files larger than 1MB
extensions={'.jpg', '.png'} # Only images
)
for group in duplicates:
print(f"Found {group.count} duplicates:")
print(f" Wasted space: {group.waste_size} bytes")
for file_path in group.files:
print(f" - {file_path}")
# Organize directory
result = herder.organize(Path("/downloads"))
print(f"Organized {result.files_organized} files")
print(f"Categories: {', '.join(result.categories_created)}")
# Get statistics
stats = herder.get_statistics(Path("/data"))
print(f"Total files: {stats['total_files']}")
print(f"Total size: {stats['total_size_mb']:.2f} MB")
File Type Categories
fileherder automatically categorizes files into:
- code - Python, JavaScript, Java, C++, etc.
- document - PDF, DOCX, MD, TXT, etc.
- image - JPG, PNG, GIF, SVG, etc.
- video - MP4, AVI, MKV, MOV, etc.
- audio - MP3, WAV, FLAC, OGG, etc.
- archive - ZIP, TAR, GZ, 7Z, etc.
- data - CSV, JSON, XML, SQL, etc.
- text - Plain text, logs, config files
- other - Uncategorized files
API Reference
Core Classes
FileHerder
Unified interface for all file management operations.
from fileherder import FileHerder
herder = FileHerder()
# Find duplicates
duplicates = herder.find_duplicates(directory, recursive=True, min_size=0)
# Organize by type
result = herder.organize(directory, dry_run=False)
# Detect file type
file_type = herder.detect_type(file_path)
# Get statistics
stats = herder.get_statistics(directory)
DuplicateFinder
Specialized duplicate file detection.
from fileherder import DuplicateFinder
finder = DuplicateFinder()
duplicates = finder.find_duplicates(
directory,
recursive=True,
min_size=1024*1024,
extensions={'.jpg', '.png'}
)
FileOrganizer
Directory organization by file type.
from fileherder import FileOrganizer
organizer = FileOrganizer()
result = organizer.organize_directory(
directory,
dry_run=False,
create_subdirs=True
)
FileTypeDetector
File type classification.
from fileherder import FileTypeDetector
detector = FileTypeDetector()
file_type = detector.detect_type(Path("script.py"))
# Returns: 'code'
Batch Operations
from fileherder.operations import (
move_files,
copy_files,
delete_files_safe,
rename_files_batch
)
# Move files
result = move_files(
files=[Path("file1.txt"), Path("file2.txt")],
destination=Path("/archive"),
overwrite=False
)
# Delete safely (with confirmation)
result = delete_files_safe(
files=duplicate_files,
require_confirmation=True
)
Data Classes
DuplicateGroup
@dataclass
class DuplicateGroup:
hash_value: str # SHA256 hash
files: List[Path] # List of duplicate files
total_size: int # Combined size of all
waste_size: int # Size of redundant copies
count: int # Number of duplicates
OrganizationResult
@dataclass
class OrganizationResult:
files_organized: int
categories_created: List[str]
category_counts: Dict[str, int]
success: bool
error: Optional[str]
Development
# Clone repository
git clone https://github.com/lukeslp/fileherder.git
cd fileherder
# Install with dev dependencies
pip install -e .[dev]
# Run tests
pytest tests/ -v
# Run tests with coverage
pytest tests/ --cov=fileherder --cov-report=html
Architecture
fileherder is designed with minimal dependencies:
- Core module (
core.py) - Pure Python, no dependencies - Operations module (
operations.py) - Batch file operations - CLI module (
cli.py) - Optional Rich interface
This allows the package to be used in environments where installing dependencies is difficult, while still offering a beautiful CLI when Rich is available.
Extracted from cleanupx
fileherder contains the core file management features from the larger cleanupx project, without LLM dependencies or complex integrations.
License
MIT License
Copyright (c) 2024 Luke Steuber
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Author
Luke Steuber
- Website: lukesteuber.com
- Email: luke@dr.eamer.dev
- Bluesky: @lukesteuber.com
- LinkedIn: lukesteuber
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fileherder-1.0.1.tar.gz.
File metadata
- Download URL: fileherder-1.0.1.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5996b1922868911bcdd955d342fa6776c0de79407bc596b08cbe9e674089ae9a
|
|
| MD5 |
e5bf59a8a6da438bc0e75554c29ddd9c
|
|
| BLAKE2b-256 |
d8a70124fb33af4dcfbbce08a157a284f59ecb77e96d24107941aadcc8d82081
|
File details
Details for the file fileherder-1.0.1-py3-none-any.whl.
File metadata
- Download URL: fileherder-1.0.1-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1714a725d8f264b00d02e25306dd5f437b6f9cc09afcfd363b1a70847d1aa996
|
|
| MD5 |
6d086950b9daddeae26eae14c6395793
|
|
| BLAKE2b-256 |
c76cecd27d15092f00a70fea5aded0dec3cc2036cec3a0ea29d4aa6223c994c1
|