juno.preview

Present arbitrary files or in-memory data in Juno’s modal preview.

The preview is the same QuickLook-based modal that pops up for matplotlib figures from a script, but reachable from any context — scripts and notebooks alike. Calling show() repeatedly during a single run appends each new entry to the already-open modal rather than replacing it; you can swipe (or use the navigation controls) to step between them. For inline rendering inside a notebook cell, use IPython.display instead.

Typical usage:

from juno import preview

preview.show("/path/to/photo.jpg")
preview.show(pil_image)
preview.show(numpy_rgb_array)
preview.show(matplotlib_figure)
preview.show(png_bytes, mime="image/png")
juno.preview.show(source, *, mime=None)

Present source in the modal preview.

Parameters:
  • source (Any) – What to preview. Accepts a file path (str or os.PathLike), raw encoded bytes (bytes, bytearray, memoryview), a PIL.Image.Image, a numpy.ndarray, or a matplotlib.figure.Figure.

  • mime (str | None) – Optional MIME type hint, used only when source is raw bytes that cannot be identified by their magic-byte prefix (e.g. "image/heic", "video/mp4").

Raises:
  • TypeError – If mime is not a string.

  • PreviewError – If source is an unsupported type, the referenced file does not exist, the byte payload is empty or cannot be identified, or the encoding step fails (e.g. unsupported NumPy dtype or shape).

Return type:

None

exception juno.preview.PreviewError

Bases: Exception

Raised when the input cannot be resolved or encoded for preview.