|
| 1 | +# python-package-size-analyzer |
| 2 | + |
| 3 | +Find and list installed Python packages sorted by size (largest first) so you can quickly identify heavy dependencies to uninstall or move to a virtual environment. |
| 4 | + |
| 5 | +## Why This Script? |
| 6 | + |
| 7 | +- **Single-file, zero dependencies** – pure Python stdlib only. |
| 8 | +- **Fast insight** – instant overview of what is bloating your global / root Python installation. |
| 9 | +- **Actionable output** – largest packages first so you can prune immediately. |
| 10 | +- **Portable** – works anywhere standard `site` module is available (Windows, macOS, Linux). |
| 11 | + |
| 12 | +> Unique Selling Point: You do _not_ need to install anything (no `pip install` step). Just run it. |
| 13 | +
|
| 14 | +## Features |
| 15 | + |
| 16 | +- Recursively calculates total on-disk size for each package directory under all discovered `site-packages` locations |
| 17 | +- Human‑readable MB output, aligned in a clean table |
| 18 | +- Sorts automatically (largest → smallest) |
| 19 | +- Ignores unreadable files gracefully (permission or transient I/O errors) |
| 20 | + |
| 21 | +## Quick Start |
| 22 | + |
| 23 | +```bash |
| 24 | +python size.py |
| 25 | +``` |
| 26 | + |
| 27 | +Example output: |
| 28 | + |
| 29 | +``` |
| 30 | +Package Size (MB) |
| 31 | +---------------------------------------------------- |
| 32 | +numpy 137.42 |
| 33 | +pandas 62.77 |
| 34 | +matplotlib 35.19 |
| 35 | +scipy 31.04 |
| 36 | +pip 12.11 |
| 37 | +setuptools 11.45 |
| 38 | +... ... |
| 39 | +``` |
| 40 | + |
| 41 | +(Your numbers will differ based on what is installed.) |
| 42 | + |
| 43 | +## When To Use This |
| 44 | + |
| 45 | +- Before committing a base Docker image – trim unnecessary global packages |
| 46 | +- Cleaning up a bloated system Python install on Windows |
| 47 | +- Auditing a CI agent or build server |
| 48 | +- Deciding which libraries to move into a virtual environment |
| 49 | + |
| 50 | +## How It Works |
| 51 | + |
| 52 | +The script: |
| 53 | + |
| 54 | +1. Uses `site.getsitepackages()` (or falls back to `site.getusersitepackages()`) |
| 55 | +2. Walks every directory directly inside each detected `site-packages` |
| 56 | +3. Sums file sizes with `os.walk` |
| 57 | +4. Outputs a sorted table (descending by size) |
| 58 | + |
| 59 | +No heuristics, no partial sampling – full recursive byte size per package directory. |
| 60 | + |
| 61 | +## SEO-Friendly Keywords (contextual) |
| 62 | + |
| 63 | +Python package size analyzer, list largest python packages, site-packages disk usage, python dependency bloat, remove large python packages, clean global python install, python script no dependencies, package size audit. |
| 64 | + |
| 65 | +## Uninstalling Large Packages (Manual Examples) |
| 66 | + |
| 67 | +Once you identify large packages you don't need globally: |
| 68 | + |
| 69 | +```bash |
| 70 | +pip uninstall package_name |
| 71 | +``` |
| 72 | + |
| 73 | +Or prefer isolating heavy libs: |
| 74 | + |
| 75 | +```bash |
| 76 | +python -m venv venv |
| 77 | +venv\Scripts\activate # Windows |
| 78 | +pip install big_package_only_when_needed |
| 79 | +``` |
| 80 | + |
| 81 | +## FAQ |
| 82 | + |
| 83 | +**Q: Does it follow symlinks?** |
| 84 | +A: It traverses directories as presented by `os.walk`; typical site-packages rarely use large symlinks. Symlinked entries count the file they point to if resolved by the OS. |
| 85 | + |
| 86 | +**Q: Will this break anything?** |
| 87 | +A: It is read-only; it only walks and sums file sizes. |
| 88 | + |
| 89 | +**Q: Can I export JSON?** |
| 90 | +A: Not in this minimal version (by design). You can pipe to a file and parse manually if needed. |
| 91 | + |
| 92 | +**Q: Why not use `pip list --format=...`?** |
| 93 | +A: `pip` does not provide recursive on-disk size summaries out-of-the-box. |
| 94 | + |
| 95 | +## Lightweight Extensibility Ideas (Optional) |
| 96 | + |
| 97 | +If you fork it, you could add: |
| 98 | + |
| 99 | +- `--top N` flag |
| 100 | +- `--min-mb` filter |
| 101 | +- CSV / JSON output |
| 102 | +- Total cumulative size banner |
| 103 | + Keep changes minimal to preserve the zero-dependency ethos. |
| 104 | + |
| 105 | +## Contributing |
| 106 | + |
| 107 | +This is intentionally small. Feel free to open: |
| 108 | + |
| 109 | +- Clear bug reports (unexpected size anomalies, cross-platform edge cases) |
| 110 | +- Tiny PRs improving readability of documentation |
| 111 | + |
| 112 | +Please avoid feature bloat. |
| 113 | + |
| 114 | +## License |
| 115 | + |
| 116 | +MIT – see `LICENSE` file. |
| 117 | + |
| 118 | +## Badge Zone |
| 119 | + |
| 120 | +_(Badges kept minimal to avoid noise)_ |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +If this helped you reclaim disk space, consider starring the repo so others can discover it. |
0 commit comments