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