Textual widget for full-color terminal image rendering (Kitty TGP, Sixel, iTerm2, half-block)
Project description
PAR Textual Image
Table of Contents
- About
- Features
- Supported Protocols
- Prerequisites
- Installing
- Quick Start
- API Reference
- Environment Variables
- Protocol Detection
- Installing for dev mode
- Contributing
- License
About
PAR Textual Image is a Textual widget (TerminalImage) that renders full-color images in a terminal TUI by auto-detecting and using the best available terminal graphics protocol.
The library was built with Textual, Rich, and Pillow.
It runs on all major terminals that support Kitty TGP, Sixel, iTerm2 inline images, or falls back to half-block ANSI rendering.
Features
- Auto-detection — probes for Kitty TGP, Sixel, and iTerm2 support at startup; falls back to half-block rendering
- Manual override —
force_protocol("kitty" | "sixel" | "iterm2" | "halfblock") - Multiple input types — file path, PIL
Image, orBytesIO - Protocol-aware sizing — uses terminal cell pixel dimensions for pixel-based protocols
- Seamless Textual integration — works as a drop-in widget with
compose()/mount() - Type-safe — fully typed codebase with strict pyright checking
Supported Protocols
| Protocol | Method | Quality | Terminal Support |
|---|---|---|---|
| Kitty TGP | Virtual placement | Full color | Kitty, KiTTY |
| Sixel | DCS escape sequences | Full color | xterm, mintty, Windows Terminal, others |
| iTerm2 | OSC 1337 inline | Full color | iTerm2 |
| Half-block | Unicode + ANSI colors | Medium | Any terminal with Unicode support |
Prerequisites
- Python 3.13 or newer
- A terminal supporting at least one of the above protocols (half-block works everywhere)
Installing
Using pip
pip install par-textual-image
Using uv
uv add par-textual-image
Using pipx
pipx install par-textual-image
Quick Start
from textual.app import App, ComposeResult
from par_textual_image import TerminalImage
class ImageViewer(App):
def compose(self) -> ComposeResult:
yield TerminalImage("photo.png")
if __name__ == "__main__":
ImageViewer().run()
Force a specific protocol
widget = TerminalImage()
widget.force_protocol("sixel")
widget.set_image("photo.png")
Use a PIL Image directly
from PIL import Image
img = Image.open("photo.png").resize((200, 100))
widget = TerminalImage(img)
API Reference
TerminalImage
The main Textual widget. Accepts an optional image source on construction.
| Method | Description |
|---|---|
TerminalImage(source=None) |
Create widget with optional file path, Image, or BytesIO |
set_image(source) |
Set / replace the current image |
force_protocol(name) |
Switch protocol ("kitty", "sixel", "iterm2", "halfblock") |
protocol_info |
Property returning (protocol_name, renderer_name) |
detect_protocol()
Auto-detect the best available protocol. Returns a string like "kitty", "sixel", "iterm2", or "halfblock".
Result is memoized — call once at startup.
query_cell_size()
Query the terminal cell pixel dimensions. Returns (width, height).
Environment Variables
| Variable | Description |
|---|---|
PAR_TERM_GRAPHICS |
Force a specific protocol (kitty, sixel, iterm2, halfblock) |
TEXTUAL_CELL_WIDTH |
Override detected cell width in pixels |
TEXTUAL_CELL_HEIGHT |
Override detected cell height in pixels |
Protocol Detection
Detection priority:
PAR_TERM_GRAPHICSenv var (if set and valid)- iTerm2 env vars (
TERM_PROGRAM=iTerm.apporLC_TERMINAL=iTerm2) - Kitty TGP probe (queries the terminal, 100ms timeout)
- Sixel probe (DA1 query checks for
4) - Fallback:
halfblock
Installing for dev mode
Clone the repo and run the setup make target. Note uv is required.
git clone https://github.com/paulrobello/par-textual-image
cd par-textual-image
make setup
Contributing
See CONTRIBUTING.md for development setup, code style, commit conventions, and the pull request process.
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 par_textual_image-0.1.0.tar.gz.
File metadata
- Download URL: par_textual_image-0.1.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e2876680e9a90d8c364421e5b0d2b804a594356210098e7268aae876b7a40ea
|
|
| MD5 |
08db9cebfbe000a7d242059edfbacfc1
|
|
| BLAKE2b-256 |
faffcb5352afa10de9d18dd7a507556a62e6060bfa00f7a7ba3ecd8018f24806
|
Provenance
The following attestation bundles were made for par_textual_image-0.1.0.tar.gz:
Publisher:
publish.yml on paulrobello/par-textual-image
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
par_textual_image-0.1.0.tar.gz -
Subject digest:
1e2876680e9a90d8c364421e5b0d2b804a594356210098e7268aae876b7a40ea - Sigstore transparency entry: 1568038794
- Sigstore integration time:
-
Permalink:
paulrobello/par-textual-image@047d9c8f47ec5166be0c83bef2fda4a54f0d1163 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/paulrobello
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@047d9c8f47ec5166be0c83bef2fda4a54f0d1163 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file par_textual_image-0.1.0-py3-none-any.whl.
File metadata
- Download URL: par_textual_image-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0b6186ef4f3e697fdfa6f5abf1c9a32ed70f1f66fb1e82bccf1099d7a85edc6
|
|
| MD5 |
4994e939acfccbd4dedee65590ec27b3
|
|
| BLAKE2b-256 |
bb970afe531fbfc680533b500aa55b01b0e89ed118552246db92cc3aff86501a
|
Provenance
The following attestation bundles were made for par_textual_image-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on paulrobello/par-textual-image
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
par_textual_image-0.1.0-py3-none-any.whl -
Subject digest:
e0b6186ef4f3e697fdfa6f5abf1c9a32ed70f1f66fb1e82bccf1099d7a85edc6 - Sigstore transparency entry: 1568038882
- Sigstore integration time:
-
Permalink:
paulrobello/par-textual-image@047d9c8f47ec5166be0c83bef2fda4a54f0d1163 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/paulrobello
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@047d9c8f47ec5166be0c83bef2fda4a54f0d1163 -
Trigger Event:
workflow_dispatch
-
Statement type: