Zum Inhalt springen

Running Python Scripts with uv: Zero Dependencies Management 🚀

Tired of setting up virtual environments and managing dependencies for simple Python scripts? Meet uv – the game-changing tool that lets you run Python scripts with external dependencies in seconds, not minutes!

What Makes uv Special?

✅ Zero Configuration – No virtual environments, no pip installs
✅ Lightning Fast – 10-100x faster than traditional tools
✅ Isolated Execution – Each script runs in its own environment
✅ PEP 723 Support – Embed dependencies directly in your scripts
✅ Cross-Platform – Works seamlessly on Windows, macOS, and Linux

Quick Examples

Run with external dependencies:

# API testing
uv run --with requests test_api.py

# Data analysis
uv run --with pandas --with matplotlib analyze_data.py

# Web scraping
uv run --with beautifulsoup4 --with requests scraper.py

Embed dependencies in your script (PEP 723):

# /// script
# dependencies = [
#   "requests>=2.31.0",
#   "rich>=13.0.0"
# ]
# requires-python = ">=3.10"
# ///

import requests
from rich.console import Console

# Your script code here...

Then simply run: uv run my_script.py

Real-World Use Cases

🔍 API Testing & Monitoring – Test endpoints without setup overhead 📊 Data Analysis – Process CSV files with pandas instantly đŸ•·ïž Web Scraping – Extract and convert web content to markdown đŸ€– Automation Scripts – System administration without environment hassle đŸ§Ș Prototyping – Experiment with new libraries immediately

Sample Output

$ uv run --with requests github_api_test.py
✅ API Response Status: 200
🏱 Organization: Astral
📍 Location: United States of America
đŸ‘„Â Public Repos: 47
⏰ Tested at: 2025-01-08 14:30:15

Why Choose uv Over Traditional Methods?

Traditional Approach:

  1. 1.
    Create virtual environment (30s)
  2. 2.
    Activate environment (5s)
  3. 3.
    Install dependencies (60s+)
  4. 4.
    Run script
  5. 5.
    Clean up
    uv Approach:
uv run --with requests my_script.py  # 2-3 seconds total!

Advanced Features

  • Python Version Management : uv run –python 3.11 script.py
  • Executable Scripts : Use shebang #!/usr/bin/env -S uv run –script
  • Version Constraints : –with ‚requests>=2.31.0,<3.0.0‘
  • Multiple Dependencies : Chain multiple –with flags
    ## Perfect For:
  • DevOps Engineers – Quick automation scripts
  • Data Scientists – Rapid prototyping and analysis
  • Web Developers – API testing and content extraction
  • System Administrators – Monitoring and maintenance scripts
  • Students & Educators – Learning without setup friction
    ## Get Started Today!
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Run your first script
uv run --with requests my_api_test.py

Ready to revolutionize your Python scripting workflow? uv eliminates the friction between idea and execution, letting you focus on solving problems rather than managing environments.

Full Article

What’s your biggest pain point with Python dependency management? Share in the comments! 👇

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert