IPython magic command for displaying images in kitty terminal
Project description
ipython-icat
Installation
You can install ipython-icat using pip:
pip install ipython-icat
Requirements
- Python 3.9+
- 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
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.Imagevalue (e.g. typingimgat the prompt) will automatically render it.
You can also run:
%icat statusto see whether integration is enabled%icat offto 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:
c.InteractiveShellApp.extensions = ['icat']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:
- Create an IPython profile if it doesn't exist (or use an existing one)
- Configure the profile to load the icat extension automatically
- 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.
Features
- Display matplotlib plots directly in kitty terminal
- Show PIL Image objects or image files
- Resize images on display
- Seamless integration with IPython workflow
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- matplotlib-backend-kitty for the original implementation
- matplotlib and Pillow for their excellent libraries
- kitty terminal for developing the graphics protocol
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ipython_icat-0.4.1.tar.gz.
File metadata
- Download URL: ipython_icat-0.4.1.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fc3555d96880f7e29e05f512a805857e618476b556c47b3e37cad35bae85982
|
|
| MD5 |
bb928844d25a71bddf8931d9f1c3b642
|
|
| BLAKE2b-256 |
f2c6d817d80a2414f400447bd3a561e9ee3db6ddbc89496f41f3ffdb56203d83
|
File details
Details for the file ipython_icat-0.4.1-py3-none-any.whl.
File metadata
- Download URL: ipython_icat-0.4.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f571c382808da1bcf92336ad3d5806262d98207aa7b4fed2bb74239666e3162f
|
|
| MD5 |
97adae6a5aeba227c89997f29568c276
|
|
| BLAKE2b-256 |
c8d9dcc335ed2cd7c037289dd9a83919762d3fe15449ca493d6b701e73866caf
|