It seems like PEP 723 inline deps are really promising now they are supported by uv.
There was a post here a week ago I think, but in general not seeing them mentioned a lot.
Are others using them? Why or why not? Any favorite use cases?
Quick illustration: If you have uv installed, then this script nytimes_in_md.py and have uv installed, you can
uv run nytimes_in_md.py
Then this will « just work » and download/install smoothly, including all deps (and Python 3.13 itself if needed!).
Script (gist):
# /// script # requires-python = « ==3.13 » # dependencies = [ # « requests>=2.32.3 », # « rich>=14.0.0 », # « markdownify>=1.1.0 », # « readabilipy>=0.3.0 », # ] # /// import requests import re from markdownify import markdownify from readabilipy import simple_json_from_html_string from rich import print from rich.markdown import Markdown # Fetch the New York Times homepage. url = « https://www.nytimes.com/ » resp = requests.get(url, headers={« User-Agent »: « Mozilla/5.0 »}) html_content = resp.text # Extract and clean up a little. article_json = simple_json_from_html_string(html_content) md: str = markdownify(article_json[« content »]) start_str = « Today’s Paper » if start_str in md: md = md.split(start_str)[1] md = re.sub(r »d+ min reads* », « », md) # Display in color in the terminal with rich. print(Markdown(md))
submitted by /u/z4lz to r/Python
[link] [comments]
Laisser un commentaire