Safe Python project cleanup utility — purge caches, build artifacts, test leftovers, and env clutter with smart protection.
Project description
pypurge is a production-grade Python cleanup utility designed to safely remove auto-generated files, caches, virtualenv leftovers, test artifacts, and temporary files — without putting your system at risk.
Think of it as a precision broom for Python projects. No more find . -name __pycache__ -delete or risky scripts.
⚡ Quick Start (The "5-Minute Rule")
Prerequisites
- Python 3.8+
- No other external dependencies required.
Installation
pip install pypurge
Run
Clean your current project interactively:
pypurge
Demo
# Preview what would be deleted without touching anything
pypurge --preview
# Clean everything, including virtual environments, older than 7 days
pypurge --clean-venv --older-than 7
✨ Features
Core
- Targeted Cleanup: Smartly handles
__pycache__,.pytest_cache,build/,dist/,.egg-info, and more. - Virtualenv Purge: Optional cleaning of virtual environments (
--clean-venv). - Smart Preview: Shows detailed counts, groups, and disk usage before you confirm deletion.
- Shell Completions: Native auto-completion for
bash,zsh, andfish.
Performance & Safety
- 🛡️ Safety-first Design: Prevents accidental root-level deletion (
/,~) and protects system directories. - Atomic Backups: Create a zip backup with SHA256 manifest before cleaning (
--backup). - Concurrency Safety: Stale lock & lockfile protection to avoid multi-process conflicts.
- Gitignore Awareness: Respects
.gitignorerules to avoid cleaning untracked files (--no-gitignoreto disable).
Advanced
- Age-based Filtering: Delete only items older than N days (
--older-than). - Configuration Wizard: Easily setup exclusions with
pypurge --init. - CI/CD Ready: Supports non-interactive modes (
--yes,--quiet,--log-format json).
🛠️ Configuration
You can configure pypurge using CLI arguments or a .pypurge.json file.
CLI Arguments
| Flag | Description | Default |
|---|---|---|
root... |
Directories to clean. | . |
-p, --preview |
Preview targets without deleting. | False |
-y, --yes |
Skip interactive confirmation. | False |
-q, --quiet |
Suppress output except errors. | False |
--clean-venv |
Include .venv, venv folders. |
False |
--exclude <pattern> |
Exclude glob or regex (re:...). |
None |
--older-than <days> |
Only target items older than N days. | 0 |
--force |
Force deletion (chmod if needed). | False |
--backup |
Create a .zip backup before delete. |
False |
--config <path> |
Path to .pypurge.json. |
Auto-detect |
--init |
Run configuration wizard. | False |
--completions <shell> |
Generate shell completions. | None |
Configuration File (.pypurge.json)
Create a .pypurge.json file in your project root for persistent settings.
{
"exclude_dirs": [".git", "node_modules"],
"exclude_patterns": ["re:.*migrations.*", "data/"],
"dir_groups": {
"CustomData": ["temp_run/", "scratch/"]
}
}
🏗️ Architecture
pypurge follows a modular architecture for safety and maintainability.
src/pypurge/
├── cli.py # Entry point
└── modules/
├── safety.py # Root/System protection logic
├── scan.py # File scanning & pattern matching
├── deletion.py # Safe removal operations
├── locking.py # Process locking mechanism
├── backup.py # Atomic backup creation
├── config.py # JSON schema validation
└── ui.py # Rich terminal output
Data Flow:
- CLI: Parses args and loads config.
- Safety: Validates target root (blocks
/,~). - Locking: Acquires
.pypurge.lock. - Scan: Walks directory tree -> Filters by rules/gitignore -> Groups targets.
- UI: Displays preview & asks confirmation.
- Backup: (Optional) Archives targets to zip.
- Deletion: Removes files/dirs.
- Cleanup: Releases lock.
🐞 Troubleshooting
| Issue | Possible Cause | Solution |
|---|---|---|
| "Operation not permitted" | File permissions or locked file. | Try --force or check file owner. |
| "Lock file is stale" | Previous run crashed or is running. | Remove .pypurge.lock or wait. |
| "Refusing to run on dangerous root" | You are running on / or ~. |
Use --allow-broad-root (Caution!). |
| No files found | .gitignore might be hiding them. |
Try --no-gitignore. |
Debug Mode:
Use --log-format text (default) or --log-format json with --log-file pypurge.log to inspect operations.
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md for details on how to set up your development environment and submit Pull Requests.
To run tests locally:
tox
🗺️ Roadmap
We are constantly improving pypurge. Check out our ROADMAP.md for upcoming features, including:
- Enhanced AI-based clutter detection.
- Plugin system for custom cleaners.
- Deeper IDE integrations.
License
MIT © Dhruv
Project details
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 pypurge-4.0.1.tar.gz.
File metadata
- Download URL: pypurge-4.0.1.tar.gz
- Upload date:
- Size: 42.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb1fd83abac6404f093e38111eb8b13c14a51c55de1cbe330eb92adeaedc5ca7
|
|
| MD5 |
ae5a61bfd4664a97191abbea2e897b0c
|
|
| BLAKE2b-256 |
563f4bd6eafd5ce851ec69aa0d6d1cce3f49e1f871d4288177cbf18f8ce3937f
|
Provenance
The following attestation bundles were made for pypurge-4.0.1.tar.gz:
Publisher:
publish.yml on dhruv13x/pypurge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypurge-4.0.1.tar.gz -
Subject digest:
eb1fd83abac6404f093e38111eb8b13c14a51c55de1cbe330eb92adeaedc5ca7 - Sigstore transparency entry: 764296361
- Sigstore integration time:
-
Permalink:
dhruv13x/pypurge@7cb7b68970f9f7bc8172f99ccd620cdf797be660 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7cb7b68970f9f7bc8172f99ccd620cdf797be660 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pypurge-4.0.1-py3-none-any.whl.
File metadata
- Download URL: pypurge-4.0.1-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
462e65a8659bdd1fefdefd8c08c816ecb608452434308b11c7419a4d092adacf
|
|
| MD5 |
9c39576196284df6cd7458abe41e2619
|
|
| BLAKE2b-256 |
0fc48240da99f1f0d9a1abf8668031051ae7aafa2706559e5c5227b3fbf76032
|
Provenance
The following attestation bundles were made for pypurge-4.0.1-py3-none-any.whl:
Publisher:
publish.yml on dhruv13x/pypurge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypurge-4.0.1-py3-none-any.whl -
Subject digest:
462e65a8659bdd1fefdefd8c08c816ecb608452434308b11c7419a4d092adacf - Sigstore transparency entry: 764296362
- Sigstore integration time:
-
Permalink:
dhruv13x/pypurge@7cb7b68970f9f7bc8172f99ccd620cdf797be660 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7cb7b68970f9f7bc8172f99ccd620cdf797be660 -
Trigger Event:
push
-
Statement type: