Zoomable microscopy, image and PDF previews in a text terminal
Whole-slide microscopy, ordinary images, and scientific PDFs, right in your terminal.
twhy is a zoomable, full-screen image viewer made of actual terminal characters. Open an OME-TIFF, SVS, or OME-Zarr slide, explore multichannel fluorescence, inspect a PNG, or page through a PDF. No browser, image server, X11, graphics protocol, or GPU required.
I had a use case for this on a remote cluster with thousands of images. Sometimes I just needed the tissue's shape, a rough count of regions of interest, or to tell a big chunk of tissue from a few tiny core needle biopsies. An ASCII-art representation of a preview from the image pyramid seemed like it would do the job.
Then working in tmux, switching the active area of the terminal with either the mouse or keyboard, got me wondering... just how far can we push a text-based image viewer? And thus began twhy. I've been having a little fun with AI slop along the way, and now it opens PDFs and lets me draw polygons on pathology images. It's ridiculous, but I'm actually going to use it.
Real terminal footage: 59-channel multiplex microscopy, DAPI and CD8. Channel selection and zoom, no mock interface.
These are short, automatically looping recordings of twhy itself. Click any clip to view it at full GIF size.
Python 3.11+. The PyPI distribution, terminal command, and Python import all share the name twhy.
Install the standalone command without changing packages in a scientific Python environment:
uv tool install twhy # or: pipx install twhy # or: python -m pip install twhy From a cloned checkout, for development:
python -m pip install -e '.[dev]' PDF support is included in the standard install. No special extra or system PDF converter is needed.
twhy photo.png # PNG, JPEG, WebP, and more twhy paper.pdf # page navigation and progressive detail twhy slide.svs # Aperio whole-slide RGB twhy slide.ome.tif # OME-TIFF, grayscale or multichannel twhy /data/sample.ome.zarr # local OME-Zarr # Compose two fluorescence channels with chosen colors: twhy slide.ome.tif --channel 0 --channel 2 \ --channel-color 0 blue --channel-color 2 cyan The initial view fits the image. Wheel zoom is anchored to the pointer; pan with the mouse or arrow keys. The terminal sidebar keeps channels, colors, and contrast controls at hand.
twhy works over ordinary terminal sessions, including environments where a desktop image viewer is inconvenient. It is an exploratory display, not a color-managed diagnostic viewer and not a substitute for measuring the original pixels.
The useful part of the joke: draw regions in twhy, save their coordinates as GeoJSON, and let Omeify extract them from the original image. This example uses a calibrated OME-TIFF, series 0. You also need the omeify command on your PATH; with isolated tool installs, install it separately using uv tool install omeify.
# Open the source and choose where to save the annotations. twhy slide.ome.tif --series 0 --output-geojson-clip regions.geojson Zoom to the view you need, then press s for a rectangle or v for a polygon and draw. Close a polygon with Enter; a adds another region in the same view. Press Shift+J to save all the regions before quitting.
# Export one full-resolution image per region, with lossless compression. omeify crop slide.ome.tif --series 0 \ --geojson regions.geojson -o regions.ome.tif \ --shatter by_index --compression Deflate --no-overwrite This writes regions-01.ome.tif, regions-02.ome.tif, and so on, retaining all channels from the selected series. Omit --shatter by_index to put the regions into separate image series in one OME-TIFF instead.
Full-resolution pixels, not a screenshot: Omeify reads the original image, not the terminal preview. Polygon crops use their bounding rectangles, not polygon masks; keep the GeoJSON for the outlines. Use the same source image, series, and orientation in both steps. Annotation placement follows the terminal grid, so zoom in before drawing for finer boundaries. More crop options.
For advanced flags, channel/series semantics, color modes, cache limits, clipboard behavior, and format caveats, use the full reference. Architecture notes are in docs/architecture.md.
The repo includes a deterministic fixture generator that creates public-safe, synthetic tissue-like RGB and multichannel OME-TIFFs. It is a renderer demonstration, not a biological simulation.
python examples/make_demo.py --output-directory /tmp/twhy-demo twhy /tmp/twhy-demo/synthetic-mif.ome.tif --channel 0 --channel 2 Python API import numpy as np from twhy import TextRenderer pixels = np.linspace(0, 1, 256**2).reshape(256, 256) frame = TextRenderer(mode="detail", color=False).render(pixels, columns=80) print(frame.to_text()) Optional remote sources Local files are the main workflow. twhy also supports HTTP(S) images/PDFs (bounded download) and HTTP(S) OME-Zarr (regional chunk reads). For native S3 or S3-compatible stores, install twhy[s3] and use your normal AWS credentials or an endpoint override. No S3 setup is needed for local images, slides, or PDFs. Remote input reference.
These GIFs are edited recordings of the real twhy terminal viewer. Showcase sources:
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




