Skip to main content

IPython magic command for displaying images in kitty terminal

Project description

ipython-icat

PyPI version

Installation

You can install ipython-icat using pip:

pip install ipython-icat

Requirements

  • Python 3.10+
  • IPython
  • matplotlib
  • Pillow (PIL)
  • terminal emulator with support for kitty graphics protocol (KGP) e.g., kitty, ghostty

Usage

Loading the Extension

In your IPython session, load the extension:

%load_ext icat

For startup files, Neovim terminals, or other launchers that should enable the backend immediately after loading the extension, set:

IPYTHON_ICAT_AUTO=1

Displaying Matplotlib Plots

To enable icat integration for both matplotlib plots and automatic PIL image rendering:

%icat

After running this command:

  • Matplotlib plots will be displayed directly in your kitty-compatible terminal.
  • Evaluating a PIL.Image.Image value (e.g. typing img at the prompt) will automatically render it.

You can also run:

  • %icat status to see whether integration is enabled
  • %icat off to disable auto-rendering and restore the previous matplotlib backend (best-effort)

Use as a Default Backend

To set the kitty backend for matplotlib as the default, add the following lines to your IPython configuration file:

  1. c.InteractiveShellApp.extensions = ['icat']
  2. c.InteractiveShellApp.exec_lines = ['%icat on']

Automatic Setup

You can quickly set up IPython to use the icat extension using the setup command:

python -m icat setup

This command will:

  1. Create an IPython profile if it doesn't exist (or use an existing one)
  2. Configure the profile to load the icat extension automatically
  3. Set matplotlib to use the icat backend by default

Additional options:

  • --profile NAME - Use a specific profile instead of the default
  • --ipython-path PATH - Specify a custom path to the .ipython directory

Example with custom profile:

python -m icat setup --profile myprofile

Displaying Images

To display an image file, a PIL Image object, or a Python expression that evaluates to a PIL Image:

%icat path/to/your/image.jpg

or

from PIL import Image
img = Image.open('path/to/your/image.jpg')
%icat img

Expressions work too:

%icat ds[0].image

You can also resize the image when displaying:

%icat path/to/your/image.jpg -W 300 -H 200

Using Ghostty

If you'd like to use this plugin with Ghostty, make sure to install the static kitten binary which will allow you to run kitten icat.

Using Full-Screen Terminal Apps

ipython-icat can render through full-screen terminal programs, such as Neovim terminal buffers, by asking kitten icat to emit Kitty unicode placeholders. Enable that mode with:

IPYTHON_ICAT_PLACEHOLDER=1

The placeholder path is configured with environment variables:

  • IPYTHON_ICAT_CELL_PIXELS=WIDTHxHEIGHT supplies the terminal cell size in pixels. This lets kitten icat compute the window size when IPython is running inside an embedded terminal.
  • IPYTHON_ICAT_WINDOW_SIZE=COLS,ROWS,WIDTH_PX,HEIGHT_PX overrides the computed window size completely.
  • IPYTHON_ICAT_TRANSFER_MODE=stream|file|memory|detect selects the Kitty graphics transfer mode. The default is stream, which works reliably through Neovim and Ghostty.
  • IPYTHON_ICAT_PASSTHROUGH=none|tmux|detect controls whether kitten icat wraps graphics commands for tmux. The default is none; use this when a host program relays the graphics request itself.

pyrepl.nvim sets these variables automatically when starting IPython and relays Kitty graphics requests from the embedded terminal to the host terminal.

Features

  • Display matplotlib plots directly in kitty terminal
  • Show PIL Image objects or image files
  • Resize images on display
  • Seamless integration with IPython workflow
  • Kitty unicode-placeholder support for embedded terminal workflows

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipython_icat-0.5.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipython_icat-0.5.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file ipython_icat-0.5.0.tar.gz.

File metadata

  • Download URL: ipython_icat-0.5.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ipython_icat-0.5.0.tar.gz
Algorithm Hash digest
SHA256 c41e606bc51f506c618fd5f07f67240ee2c26a3e1b609411336e73b23c813db8
MD5 f7de697e8d0548685f14a98500676ff7
BLAKE2b-256 33899a6e64cc1c96ef4e348edea29e5a7eb926752c609b48c8f6e52a57ef090e

See more details on using hashes here.

File details

Details for the file ipython_icat-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: ipython_icat-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ipython_icat-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67e01ac97d8b4b563a3b78ef34764d7aacdddafbd74c6925372f0dcd9e037a1f
MD5 101d3fb22f5b6b1de6e86ef85884562a
BLAKE2b-256 408f9e2a993b5b0aae9a0962ecadd44ffa8a8dc14bb8bdd617252f9385bfab13

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page