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-1.0.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

pypurge-1.0.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pypurge-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3a34dbd151c846c2074b609af129a974f458d881aaea9366afb91d7b0695f6eb
MD5 bfbada301945a31f8c0d143c9ca3bb3c
BLAKE2b-256 f6549966664d4912a02392080b42f6be7b9297e8918f39eb2d2d26340807d87a

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for pypurge-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a77f2df03989bd91590f9319d728082caf02005b719d5e4d918496ff75045f40
MD5 46b4329446db898501a938fddbbed152
BLAKE2b-256 16aca18a417c2837e864322fa7c44cec7af32ee21cc21167f5ee0138ebaa3243

See more details on using hashes here.

Provenance

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