Skip to main content

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

Metadata

Release files for pyshrink 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyshrink 1.0.2
File Size Uploaded Provenance
pyshrink-1.0.2.tar.gz 20.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyshrink 1.0.2
File Interpreter ABI Platform
pyshrink-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.3 kB

Release files / pyshrink-1.0.2.tar.gz

Download URL pyshrink-1.0.2.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a31f64b3622afcee0544f064a92ddef2e4326e8dc0f203d950cf84ef60f94685
BLAKE2b-256 checksum
How to use checksums
e07f10abb8f8c7dfd756d3927ee08b3680bb5c0b09923dde89a2093857599212
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / pyshrink-1.0.2-py3-none-any.whl

Download URL pyshrink-1.0.2-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6adf3ee7abcbaeecf3d283ddd9aeb5b512fb48275419bad52315ef09b638a16b
BLAKE2b-256 checksum
How to use checksums
f9ce51841a8563bd29dbd8944435289f78bbdd368d477795b93c08dc5d3f07c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for pyshrink 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page