←back to thread

741 points chirau | 4 comments | | HN request time: 1.288s | source
Show context
leonheld ◴[] No.44358181[source]
I adore the

  uv add <mydependencies> --script mycoolscript.py
And then shoving

  #!/usr/bin/env -S uv run
on top so I can run Python scripts easily. It's great!
replies(5): >>44358268 #>>44358400 #>>44358419 #>>44358467 #>>44361042 #
1. simonw ◴[] No.44358467[source]
I built a Claude Project with special instructions just teaching it how to do this, which means it can output full scripts for me with inline dependencies based on a single prompt: https://simonwillison.net/2024/Dec/19/one-shot-python-tools/

Claude 4's training cutoff date is March 2025 though, I just checked and it turns out Claude Sonnet 4 can do this without needing any extra instructions:

  Python script using uv and inline script dependecies
  where I can give it a URL and it scrapes it with httpx
  and beautifulsoup and returns a CSV of all links on
  the page - their URLs and their link text
Here's the output, it did the right thing with regards to those dependencies: https://claude.ai/share/57d5c886-d5d3-4a9b-901f-27a3667a8581
replies(3): >>44358511 #>>44359003 #>>44364481 #
2. varunneal ◴[] No.44358511[source]
claude sonnet typically forgets about uv script syntax in my experience. I usually find myself having to paste in the docs every time. By default it wants to use uv project syntax.
3. sunaookami ◴[] No.44359003[source]
Using your system instructions for uv for every LLM now since first seeing your post last year, thanks! It's insanely helpful just asking e.g. Claude to give me a python script for XYZ and just using "uv run". I also added:

  If you need to run these scripts, use "uv run script-name.py". It will automatically install the dependencies. Stdlibs don't need to be specified in the dependencies array.
since e.g. Cursor often gets confued because the dependencies are not installed and it doesn't know how to start the script. The last sentence is for when LLMs get confused and want to add "json" for example to the dependency array.
4. bilbo-b-baggins ◴[] No.44364481[source]
Bro I gotchu

https://github.com/shakefu/cursor-rules/blob/f4dffbbf04ce99f...