Trying out Python packages with ipython and uvx

I figured out a really simple pattern for experimenting with new Python packages today:

uvx --with llm --with sqlite-utils ipython

This command will work if you have uv installed and nothing else. It uses uvx to install and run the excellent ipython Python REPL in a new, dedicated virtual environment with two additional Python libraries - llm and sqlite-utils. You don't need to install ANY of those packages first - uvx will fetch and cache them the first time you run this, and reuse the cached versions on future invocations.

Screenshot of the command running - I can then import llm and sqlite_utils and start using them.

You can also set which Python version will be used with the --python 3.13 option:

uvx --python 3.13 --with llm --with sqlite-utils ipython

I turned this into a shell script (with help from Claude):

#!/bin/sh
# itry - A portable script for launching ipython with uvx packages

# Show help if requested
[ "$1" = "--help" ] && {
    echo "Usage: itry [packages...]"
    echo "Example: itry llm sqlite-utils datasette"
    exit 0
}

# Initialize empty string for packages
PACKAGES=""

# Process all arguments, adding --with before each
for arg in "$@"; do
    PACKAGES="$PACKAGES --with $arg"
done

# Remove leading space if present
PACKAGES="${PACKAGES# }"

# Execute uvx command with Python 3.13
exec uvx $PACKAGES --python 3.13 ipython

This is saved as ~/.local/bin/itry - then chmod 755 ~/.local/bin/itry - and now I can jump straight into an interactive ipython REPL with any Python packages I like using this command:

itry cowsay

Then:

import cowsay
cowsay.cow("hello")
  _____
| hello |
  =====
     \
      \
        ^__^
        (oo)\_______
        (__)\       )\/\
            ||----w |
            ||     ||

Created 2025-02-13T23:34:47-08:00 · Edit