Skip to main content

Safe Python project cleanup utility — purge caches, build artifacts, test leftovers, and env clutter with smart protection.

Project description


🧹 pypurge — Safe & Powerful Python Project Cleaner

pypurge is a production-grade Python cleanup utility designed to safely remove auto-generated files, caches, virtualenv leftovers, test artifacts, temporary files, and clutter — 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 — clean confidently, with safety rails.


✅ Key Features

  • 🔐 Safety-first design — prevents accidental root-level deletion
  • 🎯 Python-specific cleanup
    • __pycache__/, *.pyc, .pytest_cache/, .mypy_cache/, .ruff_cache/, build/, dist/, etc.
  • 🧠 Smart preview mode — shows counts, groups & disk usage before deleting
  • 🪪 Stale lock & lockfile protection — avoids multi-process conflicts
  • 🕒 Age-based filtering — delete only items older than N days
  • 📦 Atomic backup mode — zip backup with SHA256 manifest
  • 🧪 Cleans testing & packaging leftovers
  • 🧹 Optional virtualenv purge
  • 💬 Colored interactive interface (or JSON for automation)
  • 🛑 Root & dangerous directory protection
  • ⚙️ Configurable via JSON (.pypurge.json)
  • 🤖 Works safely in CI & scripts

📦 Installation

pip install pypurge

Or in development mode:

pip install -e .


---

🚀 Usage

Clean current project interactively

pypurge

Preview everything  no deletions

pypurge --preview

Clean without prompt (CI-safe)

pypurge --yes

Clean a specific folder

pypurge myproject/

Backup before deleting 🛟

pypurge --backup

Clean virtual environments too

pypurge --clean-venv

Delete only files older than 7 days

pypurge --older-than 7

Allow root / system scans (⚠️ expert mode)

pypurge --allow-root --allow-broad-root


---

✨ Example Output

=== Preview: grouped cleanup summary for .
Group                         Items   Size        Paths (truncated)
----------------------------------------------------------------------
Python Caches                 84      12.4MB
Testing/Linting/...           36      4.2MB
Build/Packaging               12      2.1MB

📁 Python Caches  84 items, 12.4MB
  src/app/__pycache__/        340KB
  tests/__pycache__/          290KB
  ...
... and 60 more


---

⚙️ Configuration

Create a .pypurge.json in your project root:

{
  "exclude_patterns": ["re:.*migrations.*"],
  "dir_groups": {
    "CustomGroup": ["temp_run", "scratch"]
  }
}


---

🔒 Safety Rules

By default pypurge REFUSES to run in:

/

$HOME

/usr, /etc, /bin, /sbin


Unless you explicitly pass:

--allow-broad-root

Running as root also requires:

--allow-root


---

🤝 Trusted Publishing & CI

This project uses PyPI Trusted Publishing (OIDC) + GitHub Actions for secure releases.

Push tag to publish:

git tag v0.1.0
git push origin v0.1.0


---

🧠 Requirements

Python >= 3.10

No runtime dependencies



---

🪪 License

MIT © Dhruv


---

⭐ Support the Project

If this tool saved you from rm -rf nightmares…
Give it a  on GitHub  it helps a lot!


---

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

pypurge-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypurge-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file pypurge-0.1.0.tar.gz.

File metadata

  • Download URL: pypurge-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pypurge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49487d35900fbe39826cc543c04ff9283bbdb1589d7a00fab9fff754d26b5dfd
MD5 38e530fe9db7c84ec203862adef82416
BLAKE2b-256 b5dfd9df395e1a356bd8a4ca9c88f2508b5d555210775d9b2d6c65408a08cb06

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypurge-0.1.0.tar.gz:

Publisher: publish.yml on dhruv13x/pypurge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pypurge-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pypurge-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pypurge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 388b96e7274bfae08b0fc45d59b9741f0cba1a39137e32067b30733101bd608b
MD5 6fb73d84f5ebb9a15c40fad9746fa942
BLAKE2b-256 6b07cb459897ab0a86ffa1b186f56818d1fe9dd0d277ed2f687c813cd9ec005d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypurge-0.1.0-py3-none-any.whl:

Publisher: publish.yml on dhruv13x/pypurge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page