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/yourusername/pyshrink.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)

🔧 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.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.

pyshrink-1.0.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyshrink-1.0.0.tar.gz
  • Upload date:
  • Size: 19.9 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.0.tar.gz
Algorithm Hash digest
SHA256 5f44b2625eb0d3c5abdf144929b7e596f9a5d48b39ce1a3e23a52f190031a88d
MD5 ee1d226b5f52993e16989d2dcd24c7fb
BLAKE2b-256 2225066457a1c7b6269d88e05e73f574a6857f590e0405b3fc35aeb593871311

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyshrink-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2969e39651cce666eb81bc69525c16f8888b7f8d88d40145f1ad5a544b214d22
MD5 92a872dbff8566ec01d24cca0030ad8c
BLAKE2b-256 0c81f849fd13aa11f55abe59c6fff0b4342a788758bafb0edea356a61e7098f3

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