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.txtor 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.
uvreceives a lot of praise: it supports PEP 723–style/// scriptheaders withdependencies = [...], 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-shellshebang 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.runis highlighted as the “workhorse” for calling external commands, withcheck,capture_output, andtextoptions;asyncio.subprocessfor concurrency.- Third-party helpers like
sh, Plumbum, pyp/pawk are discussed;shreceives 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.