Skip to main content

Clean and shrink Python projects by removing junk files and packaging them efficiently

Project description

PyShrink - Python Project Cleaner & Packager

🚀 PyShrink is a command-line tool that helps you clean, shrink, and package Python projects by removing unnecessary files and creating distributable ZIP archives.

Perfect for sharing projects in enterprise environments where you need clean, minimal code packages without Git repositories or development artifacts.


✨ Features

  • 🧹 Smart Cleanup: Removes __pycache__, .pyc, .pytest_cache, .git, virtual environments, and other junk files
  • 📦 Auto-Packaging: Creates timestamped ZIP files of cleaned projects
  • 📝 README Generation: Optionally creates README.md with project structure
  • 📋 Requirements Detection: Automatically generates or validates requirements.txt
  • 🎨 Rich CLI: Beautiful terminal output with colors and progress indicators
  • 🔒 Safe Operation: Always works on a copy - original project stays untouched
  • Multiple Modes: Interactive, automated, or full cleanup modes

📦 Installation

From PyPI (Recommended)

pip install pyshrink

From Source

git clone https://github.com/nitinkumar30/pyshrink-vscode.git
cd pyshrink
pip install -e .

🚀 Quick Start

Interactive Mode (Recommended for first-time users)

pyshrink

You'll be prompted to:

  1. Enter the project path
  2. Choose whether to create/validate requirements.txt
  3. Choose whether to create README.md

Specify Project Path

pyshrink --path /path/to/your/project

Auto-create README and Requirements

pyshrink --path /path/to/your/project --readme --req

Full Cleanup (No README, No Requirements)

pyshrink --path /path/to/your/project --full

📖 Usage Examples

Example 1: Clean Current Directory Interactively

cd my-python-project
pyshrink --path .

Interactive prompts will guide you through the process.

Example 2: Quick Cleanup with All Options

pyshrink --path ./my-project --readme --req

This will:

  • Create a copy of your project
  • Generate/validate requirements.txt
  • Create README.md if missing
  • Remove all junk files
  • Create a ZIP file with timestamp

Example 3: Minimal Package (No Docs)

pyshrink --path ./my-project --full

This creates the smallest possible package - no README, no requirements, just clean code.


🎯 What Gets Removed?

PyShrink removes common Python development artifacts:

Files Removed:

  • *.pyc - Python bytecode
  • *.pyo - Optimized bytecode
  • *.pyd - Python DLL
  • .DS_Store - macOS metadata
  • Thumbs.db - Windows thumbnails
  • *.log - Log files
  • *.tmp, *.temp - Temporary files

Directories Removed:

  • __pycache__/ - Python cache
  • .pytest_cache/ - Pytest cache
  • .mypy_cache/ - MyPy cache
  • .git/ - Git repository
  • .venv/, venv/, env/ - Virtual environments
  • *.egg-info/ - Package metadata
  • build/, dist/ - Build artifacts
  • node_modules/ - Node.js packages (if present)

📋 Command-Line Options

usage: pyshrink [-h] [--path PATH] [--req] [--readme] [--full]

Clean and package Python projects

options:
  -h, --help   show this help message and exit
  --path PATH  Path to the Python project to clean
  --req        Automatically create/validate requirements.txt
  --readme     Automatically create README.md if missing
  --full       Full cleanup (no README, no requirements)

⚡Working

PyShrink VS Code extension


🔧 How It Works

  1. Creates a Safe Copy: PyShrink copies your project to a new directory with a timestamp (e.g., myproject_pyshrink_20240207_143022)

  2. Optional README: Generates a basic README.md with project structure if requested

  3. Optional Requirements: Scans your code for imports and creates requirements.txt if requested

  4. Deep Cleanup: Recursively removes all junk files and directories

  5. Creates ZIP: Packages everything into a clean ZIP file

  6. Original Untouched: Your original project directory remains completely unchanged


📂 Output Structure

After running PyShrink, you'll get:

/path/to/project/                    # Your original (unchanged)
/path/to/project_pyshrink_TIMESTAMP/ # Clean working copy
/path/to/project_pyshrink_TIMESTAMP.zip  # Final package

🎨 Rich CLI Interface

PyShrink uses the Rich library for beautiful terminal output:

  • ✅ Colored success messages
  • ❌ Clear error messages
  • ⚠️ Helpful warnings
  • 📊 Clean progress indicators
  • 🎨 Syntax highlighting

🔍 Requirements Detection

When you use --req, PyShrink:

  1. Scans all .py files in your project
  2. Extracts import and from X import statements
  3. Filters out standard library modules
  4. Creates requirements.txt with detected packages
  5. Warns about packages it couldn't determine versions for

⚙️ VS Code Extension

PyShrink also has a VS Code Extension that provides:

  • 🎯 Command Palette integration
  • 📁 Automatic workspace detection
  • 🖥️ Interactive terminal execution
  • ⚡ Quick access to all PyShrink modes

Install from VS Code Marketplace: Search for "PyShrink"


🤝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE.txt file for details.


🐛 Bug Reports & Feature Requests

Found a bug or have a feature request? Please open an issue on GitHub Issues.


🙏 Acknowledgments

  • Built with Rich for beautiful terminal output
  • Inspired by the need for clean code sharing in enterprise environments

📊 Project Stats

  • Language: Python 3.7+
  • Dependencies: Rich (for CLI)
  • License: MIT
  • Status: Active Development

Enjoy using PyShrink! 🚀

Made with ❤️ for Python developers who value clean code

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

pyshrink-1.0.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

pyshrink-1.0.1-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file pyshrink-1.0.1.tar.gz.

File metadata

  • Download URL: pyshrink-1.0.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for pyshrink-1.0.1.tar.gz
Algorithm Hash digest
SHA256 665b7735cc6dbf4ffd6772642f617d41eeddef863ff8cdb5f007680781d37658
MD5 e73eaac16d6c8a8df3c489350b9f3801
BLAKE2b-256 24ad531e7bcd91d48b566d01c8ba0d69232c45e008446415f3d689e7668720b1

See more details on using hashes here.

File details

Details for the file pyshrink-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyshrink-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for pyshrink-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5b5f45de1096ee54e94336a38e8b3250a9be697a975681d59feba58fbebf3d1
MD5 875148fd9a94b2a0440545893ff54c0e
BLAKE2b-256 76146e0ce390ad19222df76ccbf17dd4cb529ce481288396a7b9b19aa2cea5ac

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