Skip to main content

npkill for Python โ€” Intelligent Environment Cleaner

Project description

venvkill ๐Ÿ๐Ÿ’€

npkill for Python โ€” Intelligent Python Environment Cleaner

PyPI version Python 3.9+ License: MIT

venvkill is a powerful CLI tool that scans your system for Python virtual environments, analyzes them, scores them by deletion priority, and safely cleans them up โ€” freeing gigabytes of disk space.


โœจ Features

  • ๐Ÿ” Smart Scanning โ€” Detects venv, .venv, env, conda, poetry, and pipenv environments
  • ๐Ÿ“Š Metadata Analysis โ€” Size, Python version, package count, last-used date
  • ๐Ÿง  Scoring Engine โ€” Ranks environments by deletion priority (size + age + broken status)
  • ๐ŸŽจ Rich UI โ€” Color-coded, sortable, interactive terminal tables
  • ๐Ÿ›ก๏ธ Safe Deletion โ€” Move to trash first, then confirm permanent delete
  • ๐Ÿ“ฆ Cache Detection โ€” pip cache, __pycache__, conda cache
  • ๐Ÿ“„ JSON Export โ€” Export full report for scripting or CI pipelines
  • โšก Auto-Clean โ€” Batch delete environments unused beyond a threshold
  • ๐ŸŒ Cross-Platform โ€” Windows, macOS, Linux

๐Ÿ“ฆ Installation

pip install venvkill

Or install from source:

git clone https://github.com/harshit/venvkill
cd venvkill
pip install -e .

๐Ÿš€ Usage

Scan for environments

# Scan home directory
venvkill scan

# Scan a specific path
venvkill scan --path /projects

# Deep recursive scan
venvkill scan --deep

# Scan current directory (project mode)
venvkill scan --project

# Sort by size instead of score
venvkill scan --sort size

Example output:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚                                      Python Environments                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ID โ”‚ Name     โ”‚   Size โ”‚  Python  โ”‚ Pkgs โ”‚  Last Used โ”‚ Score โ”‚  Type  โ”‚  Status  โ”‚ Path             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  1 โ”‚ ml_env   โ”‚ 3.4 GB โ”‚  3.10.9  โ”‚  128 โ”‚  120d ago  โ”‚ 18.4  โ”‚  venv  โ”‚ INACTIVE โ”‚ /home/ml_env     โ”‚
โ”‚  2 โ”‚ .venv    โ”‚ 850 MB โ”‚  3.11.2  โ”‚   42 โ”‚   45d ago  โ”‚  4.0  โ”‚  venv  โ”‚  ACTIVE  โ”‚ /projects/.venv  โ”‚
โ”‚  3 โ”‚ old_proj โ”‚ 220 MB โ”‚ unknown  โ”‚    0 โ”‚  365d ago  โ”‚ 12.8  โ”‚  venv  โ”‚  BROKEN  โ”‚ /tmp/old_proj    โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

  Legend: โ— Active  โ— Inactive (>90d)  โ— Broken

Interactively clean environments

# Interactive selection
venvkill clean

# Dry run (preview only)
venvkill clean --dry-run

# Permanently delete (skip trash)
venvkill clean --force

# Delete all found environments
venvkill clean --all

# Only show high-priority targets
venvkill clean --min-score 5.0

Detect and clean caches

# Show cache sizes
venvkill cache

# Also scan for __pycache__ in current dir
venvkill cache --path /projects

# Clean all detected caches
venvkill cache --clean

Auto-clean inactive environments

# Delete envs unused for > 180 days (default)
venvkill auto-clean

# Custom threshold
venvkill auto-clean --days 90

# Preview only
venvkill auto-clean --dry-run

Export results

venvkill export --output report.json

Manage trash

# List trashed environments
venvkill trash

# Permanently free trashed space
venvkill trash --empty

๐Ÿง  Scoring Formula

Environments are ranked by deletion priority:

score = (size_in_gb ร— 3) + (days_unused / 30) + (broken ร— 5)
Factor Weight Reason
Size (GB) ร—3 Large envs free more disk space
Inactivity (months) ร—1 Older = more likely abandoned
Broken environment +5 No reason to keep a broken env

๐ŸŽจ Color Coding

Color Meaning
๐ŸŸข Green Active (used within 90 days)
๐ŸŸก Yellow Inactive (unused > 90 days)
๐Ÿ”ด Red Broken (missing Python interpreter)

๐Ÿ›ก๏ธ Safe Deletion

By default, venvkill moves environments to a trash folder (/tmp/venvkill_trash/) rather than permanently deleting them. This gives you a safety net.

# See what's in trash
venvkill trash

# Permanently free the space
venvkill trash --empty

Use --force to skip trash and delete immediately.


๐Ÿ“„ JSON Export

venvkill scan --json results.json

Output format:

[
  {
    "path": "/home/user/projects/ml_env",
    "type": "venv",
    "size_bytes": 3650000000,
    "size": "3.4 GB",
    "python_version": "3.10.9",
    "package_count": 128,
    "days_unused": 120,
    "broken": false,
    "inactive": true,
    "score": 18.4,
    "last_modified": "2024-10-01T12:00:00"
  }
]

๐Ÿ”ง Development

# Clone and set up
git clone https://github.com/harshit/venvkill
cd venvkill
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Build
python -m build

# Publish
twine upload dist/*

๐Ÿ“‹ Roadmap

  • GUI version (Textual TUI)
  • AI-powered recommendation engine
  • Background monitoring daemon
  • VSCode extension
  • Usage analytics mode (opt-in)

๐Ÿ“„ License

MIT ยฉ Harshit Singh


๐Ÿค Contributing

PRs and issues welcome! Please open an issue before submitting large changes.

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

venvkill-0.1.1.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.

venvkill-0.1.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file venvkill-0.1.1.tar.gz.

File metadata

  • Download URL: venvkill-0.1.1.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for venvkill-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f2a94d7cad599f6c30189be7b78894dfd9380f3af1b4eb7b6e3204fbbdeae839
MD5 125b6efa1bfcb23549efdfefd515dfe7
BLAKE2b-256 c566f69178631e13caa75030931c6a2742c1d9afe3a8a6a956b3f22e7cf96fc7

See more details on using hashes here.

File details

Details for the file venvkill-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: venvkill-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for venvkill-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac6a322a7c0e1924b385d4dd9385ab5f3abbf85565065d18de5f7e315307e6c5
MD5 6bb9f3fa0938fb03fa7b9897354d9d1e
BLAKE2b-256 82e2151397fdb880f4445103aeec678b4017e0bc741f5854f6009f427b4d5355

See more details on using hashes here.

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