Skip to main content

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

Project description

pypurge logo

PyPI version Python Wheel Release

Build status Codecov Test Coverage Code style: black Ruff Security

Downloads OS Python Versions

License: MIT

Docs


🧹 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-3.0.1.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

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

pypurge-3.0.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pypurge-3.0.1.tar.gz
Algorithm Hash digest
SHA256 eae4bef6e7a551021905b24d55c6f3dca2471269686885e46e1b55f698e6d843
MD5 584572947d2bf75300777b80b60cbaae
BLAKE2b-256 54de89482e50447369ad30e8c90bc568989546b6dae1406018d9bf39da8faea3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypurge-3.0.1.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-3.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pypurge-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cffd6795682d00bfc065d16495da974f295a751a90d782c3084085819d57f078
MD5 9886dc38c450e5c08c99685f3f8fe41b
BLAKE2b-256 5266e4c5bbf6ab965f35447e85156099eb837d25fe36de0a5af4927f32dd3ba2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pypurge-3.0.1-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