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.0.tar.gz (19.9 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.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: venvkill-0.1.0.tar.gz
  • Upload date:
  • Size: 19.9 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.0.tar.gz
Algorithm Hash digest
SHA256 01882ab57569d183e60ef7d9abf3def0c5465d61b7da1f936f5d3665fbbebcfb
MD5 ae01581d2f2a2349ad770ca246afdcbc
BLAKE2b-256 83bc9d5afdd82016132f5d6be9b6472586ed88508ce69b50ea10088db0698f25

See more details on using hashes here.

File details

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

File metadata

  • Download URL: venvkill-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ca75b5f1ecec11892b9a053fb5d7beecc754974ca865acf9099e25472865ef8
MD5 999d3505d40e074a920258870426eb08
BLAKE2b-256 2ad03ec6e5e86034fdbcdd64d341bb08535daa5aefbef3f3ac315a19a3443b98

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