Skip to content

Instantly share code, notes, and snippets.

@sdatsenko
Created February 15, 2025 06:18
Show Gist options
  • Save sdatsenko/34686685426989fa283df1e9596b4c02 to your computer and use it in GitHub Desktop.
Save sdatsenko/34686685426989fa283df1e9596b4c02 to your computer and use it in GitHub Desktop.
Running ipython with packages
#!/bin/sh
# itry - A portable script for launching ipython with uvx packages
# from https://til.simonwillison.net/python/itry
# with auto import of listed 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=""
IMPORTS=""
# Process all arguments, adding --with before each
for arg in "$@"; do
PACKAGES="${PACKAGES}--with $arg "
IMPORTS="${IMPORTS}import $arg; "
done
# Execute uvx command with Python 3.13
exec uvx $PACKAGES --python 3.13 ipython --InteractiveShellApp.exec_lines="$IMPORTS"
@sdatsenko
Copy link
Author

This is slight variation of itry script from Simon Willison’s TILs, adding automatic import of listed modules, and deleting (IMHO unnecessary) space removal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment