frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Use Python for Scripting

https://hypirion.com/musings/use-python-for-scripting
19•birdculture•4d ago

Comments

zahlman•4d ago
Dupe: https://news.ycombinator.com/item?id=46176113
mubou2•4d ago
How do you handle packages? I want scripts to a be a single file with a shebang, not a repo with a requirements.txt that I need to run in a venv. To me, this is the biggest blocker to using Python for any non-trivial scripting (which is precisely the kind where I wouldn't want to use bash), but I'd like to know how others deal with it.

C# scripts let you reference packages in a comment at the top of the file, for example:

https://devblogs.microsoft.com/dotnet/announcing-dotnet-run-...

eternityforest•4d ago
What can you do with bash that isn't in the stdlib of python?

Generally the only nontrivial scripting I ever do is associated with a larger project, so I often already have a pyproject.toml and a UV environment, and I just add the dependencies to the dev group.

mubou2•4d ago
Well, that's kind of what I mean. For scripts in a python project, you can freely use whatever packages you need. But for one-off scripts, if you need bs4 or something, you're screwed. Either your script now has external dependencies or it requires special tooling.

It just feels strange that C# of all languages is now a better scripting tool than Python, at least out of the box. I did notice uv has exactly the feature I'm looking for, though it's obviously third-party:

https://docs.astral.sh/uv/guides/scripts/#declaring-script-d...

Is everyone just using uv now instead of pip, perhaps? Or is just another alongside pipenv, conda, poetry, etc.? (Python's not my main these days, so I'm out of the loop.)

eternityforest•3d ago
UV is taking over really fast, it seems to be much more popular any other option.

I suspect conda still has some market share too but I've never needed it.

jollyllama•41m ago
I don't understand. To return to GP's point, what can you do in bash that you can't do in Python? Said in another way, what does bash offer that you would need to tackle with a dependency in Python? My understanding is that there is no such thing, and accordingly, you can still end up with something that is better than bash if you just use Python and call out to other tools with subprocess.
chillaranand•3d ago
You can specify requirements at the top of file and uv can run the script after automatically installing the dependencies.

https://avilpage.com/2025/04/learn-python-uv-in-100-seconds....

simonw•1h ago
This works really well in my experience, but it does mean you need to have a working internet connection the first time you run the script.

  # /// script
  # dependencies = [
  #     "cowsay",
  # ]
  # ///
  import cowsay
  cowsay.cow("Hello World")
Then:

  uv run cowscript.py
It manages a disposable hidden virtual environment automatically, via a very fast symlink-based caching mechanism.

You can also add a shebang line so you can execute it directly:

  #!/usr/bin/env -S uv run --script
  #
  # /// script
  # dependencies = ["cowsay"]
  # ///
  import cowsay
  cowsay.cow("Hello World")
Then:

  chmod 755 cowscript
  ./cowscript
Rucadi•1h ago
Nix allows you to do this with any language and required dependency: https://wiki.nixos.org/wiki/Nix-shell_shebang
albertoCaroM•57m ago
Whoa! This is a revelation. I already loved Nix and used nix-shell extensively, but this is the missing piece: fully reproducible Python scripts without compromise.
milliams•1h ago
https://peps.python.org/pep-0723/, e.g.:

  # /// script
  # requires-python = ">=3.11"
  # dependencies = [
  #   "requests<3",
  #   "rich",
  # ]
  # ///
  
  import requests
  from rich.pretty import pprint
  
  resp = requests.get("https://peps.python.org/api/peps.json")
  data = resp.json()
  pprint([(k, v["title"]) for k, v in data.items()][:10])
paulddraper•36m ago
> How do you handle packages?

The same way you handle them with bash?

Install them?

What are we talking about here?

a-dub•28m ago
what can you do with bash that you cannot do with the python standard library and shelling out?
N_Lens•46m ago
Weren't we already?
sevensor•28m ago
The Python stdlib does not get enough credit. People complain about things like how its http client is dated and slow, but its pretty amazing that it’s just right there if you need it, no external dependencies needed. And it’s sitting right next to difflib, graphlib, pathlib, struct, glob, tkinter, and dozens of others. Sure, every one of these is limited individually, but those limitations are stable and well understood!
rjmill•23m ago
Odd, I don't see any mention of subprocess.run, the workhorse of python scripting.

Quick rundown for the unfamiliar:

Give it a command as a list of strings (e.g., subprocess.run(["echo", "foo"]).)

It takes a bunch of flags, but the most useful (but not immediately obvious) ones are:

  check=True: Raise an error if the command fails
  capture_output=True: Captures stdout/stderr on the CompletedProcess
  text=True: Automatically convert the stdout/stderr bytes to strings
By default, subprocess.run will print the stdout/stderr to the script's output (like bash, basically), so I only bother with capture_output if I need information in the output for a later step.
tayo42•8m ago
Pretty much anything longer then a throwaway one liner I write in python.

Would be cool if python had a pipe operator though.

The back ticks in ruby is pretty ergonomic too. Wish python had a simpler way to run commands. Kind of tedious to look up subprocess run arguments and also break things up into arrays.

davidkhess•6m ago
Xonsh is perfect for this: https://xon.sh

SQLite JSON at Full Index Speed Using Generated Columns

https://www.dbpro.app/blog/sqlite-json-virtual-columns-indexing
106•upmostly•2h ago•36 comments

4 billion if statements (2023)

https://andreasjhkarlsson.github.io//jekyll/update/2023/12/27/4-billion-if-statements.html
301•damethos•6d ago•92 comments

From text to token: How tokenization pipelines work

https://www.paradedb.com/blog/when-tokenization-becomes-token
58•philippemnoel•1d ago•6 comments

Fedora: Open-source repository for long-term digital preservation

https://fedorarepository.org/
36•cernocky•2h ago•22 comments

The tiniest yet real telescope I've built

https://lucassifoni.info/blog/miniscope-tiny-telescope/
180•chantepierre•8h ago•42 comments

BpfJailer: eBPF Mandatory Access Control [pdf]

https://lpc.events/event/19/contributions/2159/attachments/1833/3929/BpfJailer%20LPC%202025.pdf
16•voxadam•1h ago•2 comments

The Tor Project is switching to Rust

https://itsfoss.com/news/tor-rust-rewrite-progress/
197•giuliomagnifico•3h ago•111 comments

Koralm Railway

https://infrastruktur.oebb.at/en/projects-for-austria/railway-lines/southern-line-vienna-villach/...
251•fzeindl•5h ago•123 comments

GPT-5.2

https://openai.com/index/introducing-gpt-5-2/
1097•atgctg•21h ago•966 comments

Show HN: Tripwire: A new anti evil maid defense

https://github.com/fr33-sh/Tripwire
31•DoctorFreeman•1d ago•18 comments

Nokia N900 Necromancy

https://yaky.dev/2025-12-11-nokia-n900-necromancy/
397•yaky•15h ago•156 comments

Google de-indexed Bear Blog and I don't know why

https://journal.james-zhan.com/google-de-indexed-my-entire-bear-blog-and-i-dont-know-why/
291•nafnlj•14h ago•119 comments

Guarding My Git Forge Against AI Scrapers

https://vulpinecitrus.info/blog/guarding-git-forge-ai-scrapers/
92•todsacerdoti•8h ago•58 comments

CRISPR fungus: Protein-packed, sustainable, and tastes like meat

https://www.isaaa.org/kc/cropbiotechupdate/article/default.asp?ID=21607
233•rguiscard•14h ago•153 comments

Use Python for Scripting

https://hypirion.com/musings/use-python-for-scripting
20•birdculture•4d ago•18 comments

Training LLMs for Honesty via Confessions

https://arxiv.org/abs/2512.08093
23•arabello•5h ago•12 comments

He set out to walk around the world. After 27 years, his quest is nearly over

https://www.washingtonpost.com/lifestyle/2025/12/05/karl-bushby-walk-around-world/
171•wallflower•4d ago•139 comments

Octo: A Chip8 IDE

https://github.com/JohnEarnest/Octo
38•tosh•6d ago•4 comments

Show HN: Autofix Bot – Hybrid static analysis and AI code review agent

19•sanketsaurav•18h ago•5 comments

Rivian Unveils Custom Silicon, R2 Lidar Roadmap, and Universal Hands Free

https://riviantrackr.com/news/rivian-unveils-custom-silicon-r2-lidar-roadmap-universal-hands-free...
349•doctoboggan•21h ago•484 comments

The highest quality codebase

https://gricha.dev/blog/the-highest-quality-codebase
593•Gricha•3d ago•367 comments

What folk can do

https://folk.computer/guides/what-folk-can-do
27•luu•4d ago•13 comments

Berlin Approves New Expansion of Police Surveillance Powers

https://reclaimthenet.org/berlin-approves-new-expansion-of-police-surveillance-powers
13•robtherobber•29m ago•1 comments

Denial of service and source code exposure in React Server Components

https://react.dev/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-comp...
313•sangeeth96•19h ago•197 comments

Programmers and software developers lost the plot on naming their tools

https://larr.net/p/namings.html
356•todsacerdoti•21h ago•460 comments

An SVG is all you need

https://jon.recoil.org/blog/2025/12/an-svg-is-all-you-need.html
297•sadiq•20h ago•125 comments

BehindTheMedspeak: A Spinal Tap

https://bookofjoe2.blogspot.com/2025/10/behindthemedspeak-this-is-spinal-tap.html
12•surprisetalk•5d ago•4 comments

Smartphone without a battery (2022)

https://yaky.dev/2022-09-06-smartphone-without-battery/
66•MYEUHD•8h ago•23 comments

Auto-grading decade-old Hacker News discussions with hindsight

https://karpathy.bearblog.dev/auto-grade-hn/
635•__rito__•1d ago•260 comments

Litestream VFS

https://fly.io/blog/litestream-vfs/
331•emschwartz•22h ago•80 comments