Cool LLM CLI Python uses

█████████████████████████████████████████████████████████
████ ▄▄▄▄▄ █ ▀▀▄ ▄█  ▄█▄▀▄▄▀ ▀ █▄█▄▀▀▀▀▀█▄▀▀ █ ▄▄▄▄▄ ████
████ █   █ █▄ █▀█ ▄▄██▄▄  ▄▀ ▄▄▄ ▄██▀█  ▀▀█ ▄█ █   █ ████
████ █▄▄▄█ █▀▀▄█ ▀ ▄  ▄▀▀█ ▄▄▄ ▀▀▀██ ▀▀▄▄▄▀███ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ █ █▄█▄█▄█ █ █ █▄█ ▀ █▄█▄▀▄▀ ▀ ▀▄█▄▄▄▄▄▄▄████
████▀█   ▀▄▀▄ █▀▀▄▄▀▄▀ ▄ ▄▄▄   ▄ █▄▀▄▄█▀ ▄█▄▄▄ ▄██ ▄▄████
████▄▀▀▀ ▀▄▀█ ▄ █ ▀█▄ █  ▀▀▀▀▀▄█▀▄ ▀ █ █▄  ▀▄ ▀▀▀ ▄█▄████
████▄▀ ▄  ▄▄▀▄▀▄█▀███ ▀▄▄████▄  █▄▄▄▀▄█ ▄▀█ ▄▄▀ ▀▄ ▄█████
█████ ▄▀██▄ ▄█  ██▄▄ ▀▄ ▀██▀  ▀▄▄▀ ▄▀▄ ▀▄▀   █▀█ ▄ ▄ ████
████ █  ▀▄▄██▄▄█ ▀▀▀ ▀██▄▄▄▄█ ▄██▀█ █▄   ▀ ▀█▄  ▀ ▀▄▄████
████▄▀▀ ██▄█ ▄█ ▀ █▄█▀▄█ ▄ ▀▀▀▀ ▄█   ▄█▄█▀▀▀█▄   ▄██▄████
████▀██▄ ▄▄█ █▀▀▄▄ ▀█▀▀▄ █▀▀ █ ▀ ██▄█▄██▄▄▄▄▄▀ ▄██ █▄████
████▄▀ ▄ ▄▄▄ ▄ ▄▄▄█▄▄▄▄▀▀█ ▄▄▄ █▄▀▀ ▄▄▄█▄█▄  ▄▄▄ ▄▄▄▄████
████▄▄▀▄ █▄█  ▀ █▄▄▀▀ ▀▄▀█ █▄█  ▄▄ ▀█ █   ██ █▄█  ▄▄ ████
████  ▄ ▄▄▄  █▄▀ ▄▄█▀▀▄█▀▄▄ ▄ ▄▀█▀ █▀█ █▄▀ ▄▄ ▄ ▄███ ████
████▄▀▄▄  ▄▄▀▀▀▀ ██ █▀▄▀▀ ▀▀▀▀▄█  ▄ ███ ▄▀█   ▀▀▀▄ ▄▄████
████▄▄  ▀█▄▀ █ ▄ ▀▄█▀ ▀  ▄▄ ▄▄▄▀▄█ ▄▄  ▄ █▄▄▀█▄▀ ▀▄ ▄████
████ █▀▄  ▄█▀▀██▄ ▀▄  █▀█▀  ▀▀████▄▄ ██▄███▄ ▀▄▀▄█ ▄█████
████ ▀▄██▄▄█▄▀█▀█ ▄█ ██▄▀▀█▄▄  █▄█ ▄   ▄█  █ █▄▄▄██  ████
████  ▄▀ █▄   ▀ █▄██▀ ▀ █▀▀▀▀█▀ █▄▄▄▀▀█  ▄█▄ █▄▄▄▀▄▀█████
█████ ▀▀█▄▄▄ █ █▀▀█  ▄▀  ▀▀▀▀▄▄▄█▀█▄  ▄▄██▄█▄▀▄█▄▀█ ▄████
████▄▄▄███▄▄ █  ▀ █▀▄▀▀▀   ▄▄▄  █▄▄ ▀▀██▄▄█▄ ▄▄▄ ██▄█████
████ ▄▄▄▄▄ ██▄▀██  ▄███ ▀▄ █▄█ ▀ ▄▄█▀▀▀▄▄ ▀▀ █▄█ ▄█  ████
████ █   █ █ ▄█▀▄▀▀▀▄▄█  ▀ ▄▄ ▄█ ▀█ █▄█ ▄ ▄ ▄ ▄▄ ▀▄▄ ████
████ █▄▄▄█ █▄█▄▄▄▄▄▄▄▀▀ ▀▀ █   █▀▄██▀▀▄▄█▀ ▀  ▀▄██▄▄ ████
████▄▄▄▄▄▄▄██▄███▄▄▄██▄█▄█▄██▄▄▄▄████▄█▄▄█▄█▄██▄▄▄▄▄▄████

llm is Simon Willison's command line LLM client

export OPEN_API_KEY=...
uvx llm -m gpt-4.1-nano 'What is 2 + 2?'

This is useful for quick help without leaving the terminal.

You can install plugins...

pip install llm
llm install llm-openrouter llm-gemini llm-anthropic

... and use other models.

export OPENROUTER_API_KEY=...
llm models  # list models
llm -m openrouter/deepseek/deepseek-r1:free 'What is 2 + 2?'

It can write code you can execute

llm '10th prime number' \
  --system 'Write Python code in ```python...```' \
  | tee >(cat >&2) \
  | awk '/^```/{X=!X; next} X' \
  | python -

You do need to be careful. But where's the fun in that? 😀

Let's create a function

pyrun() {
  llm "$*" \
    --model gpt-4.1-mini \
    --system 'Write CONCISE Python code inside ```python...```
Begin with inline script dependencies.
# /// script
# requires-python = ">=3.13"
# dependencies = ["pandas", ...]
# ///
import pandas as pd
...
' \
    | tee >(cat >&2) \
    | awk '/^```/{X=!X; next} X' \
    | uv run -
}

Generate data

pyrun Generate fake student data. Save as JSON and CSV
pyrun Create 5 images with random shapes and colors. Save as test-1.png, ...
pyrun Create cities.geojson with markers on the 10 most populated cities

Convert data

pyrun Convert all CSV files in this folder into parquet
pyrun Randomly add a few missing cells to all CSVs

Clean data

pyrun Create _cleaned.csv versions of all CSVs dropping missing values
pyrun Deduplicate any '*name*' column in all CSVs with fuzzywuzzy ratio of 90+

Transform data / text

pyrun Show me the Wikipedia home page as Markdown
pyrun Format README.md as Markdown and print using rich

Data science

pyrun Download the iris dataset, train a logistic regression classifier, and print the accuracy
pyrun Download the Singapore shapefile from gadm and tell me the bounding box
pyrun Find duplicate images in ./photos via perceptual hashing (imagehash) and output a CSV of dup clusters

Visualize data

pyrun "From vega_datasets flights_2k data, save daily flight count as a line chart flights.png"
pyrun Render cities.geojson as an interactive Folium map with circle markers sized by population as cities.html

Scrape & parse

pyrun Scrape the top 20 HN front-page links with BeautifulSoup and save as hn.json
pyrun Fetch all headings from https://docs.python.org/3/library/index.html and save to python_stdlib_headings.txt

Automate the browser

pyrun Using Playwright, save a screenshot of https://example.com as example.png

Real-life uses

pyrun 'Rename "Wealth Report-0786-mmm-yy.pdf" where mmm is like Jan, Feb, ... and yy is like 24, 25, ... to 20yy-mm.pdf like 2024-01.pdf, 2024-02.pdf, etc. and run it'
pyrun 'Load gen-ai-messages.json with Pandas, get time from .time (yyyy-mm-ddThh:mm:ss.xxxZ format) and print the number of rows by month as a table'

Running this talk

To initialize this slide deck, use slide.py

uv run slide.py llm-cli.md

To go to the next slide:

uv run slide.py