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.3.tar.gz (19.4 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.3-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: venvkill-0.1.3.tar.gz
  • Upload date:
  • Size: 19.4 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.3.tar.gz
Algorithm Hash digest
SHA256 ea928f593bcb4fd8c1dc428c8d217db655123a98b548786e62d1aa00b7a08f41
MD5 553b994b64764a9a11092bb74c31e61c
BLAKE2b-256 d78bd5700eab44c415dcb3f960a3fbb4994d2b504802e9437919561c12b021fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: venvkill-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c7f15b176ba1d8ed86f56594d3dcaee9d1fc089cf51d7ea81ad9677c9d58f10a
MD5 20bd5ff07d13b11cf8d20203f0177160
BLAKE2b-256 e97abd2beb49d48c352585923872aa50118bbcc377028f7193943459b78f3b04

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