# Cool LLM CLI Python uses

```
█████████████████████████████████████████████████████████
████ ▄▄▄▄▄ █ ▀▀▄ ▄█  ▄█▄▀▄▄▀ ▀ █▄█▄▀▀▀▀▀█▄▀▀ █ ▄▄▄▄▄ ████
████ █   █ █▄ █▀█ ▄▄██▄▄  ▄▀ ▄▄▄ ▄██▀█  ▀▀█ ▄█ █   █ ████
████ █▄▄▄█ █▀▀▄█ ▀ ▄  ▄▀▀█ ▄▄▄ ▀▀▀██ ▀▀▄▄▄▀███ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ █ █▄█▄█▄█ █ █ █▄█ ▀ █▄█▄▀▄▀ ▀ ▀▄█▄▄▄▄▄▄▄████
████▀█   ▀▄▀▄ █▀▀▄▄▀▄▀ ▄ ▄▄▄   ▄ █▄▀▄▄█▀ ▄█▄▄▄ ▄██ ▄▄████
████▄▀▀▀ ▀▄▀█ ▄ █ ▀█▄ █  ▀▀▀▀▀▄█▀▄ ▀ █ █▄  ▀▄ ▀▀▀ ▄█▄████
████▄▀ ▄  ▄▄▀▄▀▄█▀███ ▀▄▄████▄  █▄▄▄▀▄█ ▄▀█ ▄▄▀ ▀▄ ▄█████
█████ ▄▀██▄ ▄█  ██▄▄ ▀▄ ▀██▀  ▀▄▄▀ ▄▀▄ ▀▄▀   █▀█ ▄ ▄ ████
████ █  ▀▄▄██▄▄█ ▀▀▀ ▀██▄▄▄▄█ ▄██▀█ █▄   ▀ ▀█▄  ▀ ▀▄▄████
████▄▀▀ ██▄█ ▄█ ▀ █▄█▀▄█ ▄ ▀▀▀▀ ▄█   ▄█▄█▀▀▀█▄   ▄██▄████
████▀██▄ ▄▄█ █▀▀▄▄ ▀█▀▀▄ █▀▀ █ ▀ ██▄█▄██▄▄▄▄▄▀ ▄██ █▄████
████▄▀ ▄ ▄▄▄ ▄ ▄▄▄█▄▄▄▄▀▀█ ▄▄▄ █▄▀▀ ▄▄▄█▄█▄  ▄▄▄ ▄▄▄▄████
████▄▄▀▄ █▄█  ▀ █▄▄▀▀ ▀▄▀█ █▄█  ▄▄ ▀█ █   ██ █▄█  ▄▄ ████
████  ▄ ▄▄▄  █▄▀ ▄▄█▀▀▄█▀▄▄ ▄ ▄▀█▀ █▀█ █▄▀ ▄▄ ▄ ▄███ ████
████▄▀▄▄  ▄▄▀▀▀▀ ██ █▀▄▀▀ ▀▀▀▀▄█  ▄ ███ ▄▀█   ▀▀▀▄ ▄▄████
████▄▄  ▀█▄▀ █ ▄ ▀▄█▀ ▀  ▄▄ ▄▄▄▀▄█ ▄▄  ▄ █▄▄▀█▄▀ ▀▄ ▄████
████ █▀▄  ▄█▀▀██▄ ▀▄  █▀█▀  ▀▀████▄▄ ██▄███▄ ▀▄▀▄█ ▄█████
████ ▀▄██▄▄█▄▀█▀█ ▄█ ██▄▀▀█▄▄  █▄█ ▄   ▄█  █ █▄▄▄██  ████
████  ▄▀ █▄   ▀ █▄██▀ ▀ █▀▀▀▀█▀ █▄▄▄▀▀█  ▄█▄ █▄▄▄▀▄▀█████
█████ ▀▀█▄▄▄ █ █▀▀█  ▄▀  ▀▀▀▀▄▄▄█▀█▄  ▄▄██▄█▄▀▄█▄▀█ ▄████
████▄▄▄███▄▄ █  ▀ █▀▄▀▀▀   ▄▄▄  █▄▄ ▀▀██▄▄█▄ ▄▄▄ ██▄█████
████ ▄▄▄▄▄ ██▄▀██  ▄███ ▀▄ █▄█ ▀ ▄▄█▀▀▀▄▄ ▀▀ █▄█ ▄█  ████
████ █   █ █ ▄█▀▄▀▀▀▄▄█  ▀ ▄▄ ▄█ ▀█ █▄█ ▄ ▄ ▄ ▄▄ ▀▄▄ ████
████ █▄▄▄█ █▄█▄▄▄▄▄▄▄▀▀ ▀▀ █   █▀▄██▀▀▄▄█▀ ▀  ▀▄██▄▄ ████
████▄▄▄▄▄▄▄██▄███▄▄▄██▄█▄█▄██▄▄▄▄████▄█▄▄█▄█▄██▄▄▄▄▄▄████
```

- PyCon Singapore. 19 Jun 2025
- S Anand, LLM psychologist at Straive
- Email: root.node@gmail.com

<!--

https://github.com/sanand0/talks/blob/main/2025-06-pycon-sg/llm-cli.md

https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://github.com/sanand0/talks/blob/main/2025-06-pycon-sg/llm-cli.md

uvx --with pyqrcode qr2text --encode-text 'https://github.com/sanand0/talks/blob/main/2025-06-pycon-sg/llm-cli.md'

Ideas via https://chatgpt.com/share/6853b092-22f4-800c-ac15-3fe24e46f1ac
-->

## `llm` is Simon Willison's command line LLM client

```bash
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...

```bash
pip install llm
llm install llm-openrouter llm-gemini llm-anthropic
```

... and use other models.

```bash
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

````bash
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

````bash
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 -
}
````

<!-- llm --extract extract code, but doesn't stream output. I like seeing code & progress -->

## Generate data

```bash
pyrun Generate fake student data. Save as JSON and CSV
```

```bash
pyrun Create 5 images with random shapes and colors. Save as test-1.png, ...
```

```bash
pyrun Create cities.geojson with markers on the 10 most populated cities
```

## Convert data

```bash
pyrun Convert all CSV files in this folder into parquet
```

```bash
pyrun Randomly add a few missing cells to all CSVs
```

## Clean data

```bash
pyrun Create _cleaned.csv versions of all CSVs dropping missing values
```

```bash
pyrun Deduplicate any '*name*' column in all CSVs with fuzzywuzzy ratio of 90+
```

## Transform data / text

```bash
pyrun Show me the Wikipedia home page as Markdown
```

```bash
pyrun Format README.md as Markdown and print using rich
```

## Data science

```bash
pyrun Download the iris dataset, train a logistic regression classifier, and print the accuracy
```

```bash
pyrun Download the Singapore shapefile from gadm and tell me the bounding box
```

```bash
pyrun Find duplicate images in ./photos via perceptual hashing (imagehash) and output a CSV of dup clusters
```

## Visualize data

```bash
pyrun "From vega_datasets flights_2k data, save daily flight count as a line chart flights.png"
```

```bash
pyrun Render cities.geojson as an interactive Folium map with circle markers sized by population as cities.html
```

## Scrape & parse

```bash
pyrun Scrape the top 20 HN front-page links with BeautifulSoup and save as hn.json
```

```bash
pyrun Fetch all headings from https://docs.python.org/3/library/index.html and save to python_stdlib_headings.txt
```

## Automate the browser

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

## Real-life uses

```bash
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'
```

```bash
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](https://github.com/sanand0/scripts/blob/e2fc9c1b66c0954586357dee9c22daccf05d972a/slide.py)

```bash
uv run slide.py llm-cli.md
```

To go to the next slide:

```bash
uv run slide.py
```
