Using Python for Scripting

Dependency Handling for Python Scripts

  • Core pain point: people want single-file Python scripts with a shebang, but non-trivial scripts need external packages.
  • Some accept a simple requirements.txt or wrapper scripts that activate a venv/conda env as “good enough.”
  • Others want inline dependency declarations, similar to C# script comments or Ruby’s inline Bundler.
  • uv receives a lot of praise: it supports PEP 723–style /// script headers with dependencies = [...], auto-creates disposable venvs, caches packages, can be used via shebang, and can manage Python versions.
  • Downsides of uv: not installed everywhere (undermines “Python is everywhere”), and the first run needs internet. Workarounds mentioned include shiv (zipapp bundling) and pipx-based exec wrappers.

Python vs Bash for Scripting

  • Several argue that anything non-trivial should move from bash to a “real” language; Python is much more readable, maintainable, and powerful.
  • Critics ask what bash can do that Python (stdlib + subprocess) cannot; consensus is that bash scripts often get complex because of bash, not despite it.
  • Counterpoint: system package managers make bash-based tooling straightforward, while Python’s multiple packaging tools (pip, pipx, conda, poetry, uv…) are seen by some as confusing and fragile.

Tooling: Nix and Other Ecosystem Solutions

  • Nix’s nix-shell shebang and flakes are praised for making any-language scripts (including Python) fully reproducible with pinned dependencies.
  • Pushback: Nix’s learning curve and perceived complexity make it overkill “just to auto-install some dependencies.”
  • Some defend Nix as no worse than other package managers when used simply, and very robust once understood.

Python Stdlib, subprocess, and Helpers

  • Many comments emphasize how strong the Python stdlib is for scripting: HTTP, sqlite, tkinter, JSON, diffs, globbing, etc., with no extra packages.
  • subprocess.run is highlighted as the “workhorse” for calling external commands, with check, capture_output, and text options; asyncio.subprocess for concurrency.
  • Third-party helpers like sh, Plumbum, pyp/pawk are discussed; sh receives criticism for unsafe defaults (TTY behavior, hidden stderr).

Portability, Stability, and Alternatives

  • Some challenge the article’s claim that Python 3 is on “basically every machine”; in practice there may be multiple versions or none.
  • Concerns: unmaintained Python scripts often break on new interpreter versions; dependency installation without root can be painful.
  • Alternatives mentioned for “scripting”: Rust (XTask), Go, Nim, Janet, JavaScript, xonsh, Nushell, Perl (with mixed reception). Static binaries are valued where long-term, dependency-free deployment matters.