Skip to main content

wskr

A modular, pluggable Matplotlib “image‐in‐terminal” backend.

What is wskr?

wskr lets you render Matplotlib figures as inline images in terminals that support Kitty, iTerm2, or Sixel protocols. It cleanly separates:

  • Transports (wskr.tty.*): how to talk to the terminal (e.g. Kitty image protocol, Sixel, etc.).
  • Backends (wskr.mpl.*): a generic Matplotlib FigureCanvas/FigureManager that uses a Transport to size and send a PNG.
  • Rich integration (wskr.rich.*): display plots in a rich console using the same transport layer.

Features

  • Kitty backend out of the box (via KittyTransport)
  • Planned support for iTerm2 & Sixel
  • Registry of transports so you can add new protocols without touching Matplotlib code
  • Automatic resizing to fill your terminal viewport while preserving aspect ratio
  • rich renderables for embedding plots in TUI applications

Installation

pip install wskr

Quick start

import matplotlib
# choose one of: wskr (generic), wskr_kitty, wskr_sixel, wskr_iterm2
matplotlib.use("wskr_kitty")
import matplotlib.pyplot as plt

# make a simple plot...
plt.plot([0, 1, 2], [10, 20, 15], marker="o")
plt.title("Hello, terminal!")
plt.show()   # renders inline via Kitty protocol

Using with Rich

from rich.console import Console
from jkit.plot import make_plot_grid
from wskr.rich.plt import RichPlot

console = Console()
fig, ax = make_plot_grid(1, 1)
ax.plot([0,1,2], [2,3,1], c="w")
rich_plot = RichPlot(fig, desired_width=40, desired_height=10)
console.print(rich_plot)

Extending to new protocols

To add a new terminal protocol (e.g. MyTerm) for inline Matplotlib rendering:

✅ Step 1: Implement a Custom Transport

Create a class that inherits from ImageTransport and implements:

from wskr.tty.base import ImageTransport

class MyTermTransport(ImageTransport):
    def get_window_size_px(self) -> tuple[int, int]:
        # return (width_px, height_px)
        ...

    def send_image(self, png_bytes: bytes) -> None:
        # display image in terminal
        ...

    def init_image(self, png_bytes: bytes) -> int:
        # optional: upload image once, return an ID
        ...

Then register it:

from wskr.tty.registry import register_image_transport
register_image_transport("myterm", MyTermTransport)

✅ Step 2: Define a Matplotlib Backend

Use the shared base classes for minimal boilerplate:

import matplotlib.pyplot as plt
from matplotlib import _api
from matplotlib.backend_bases import _Backend
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib._pylab_helpers import Gcf

from wskr.mpl.base_backend import BaseFigureManager
from myterm_module import MyTermTransport  # your transport from Step 1

plt.style.use("dark_background")


class MyTermFigureManager(BaseFigureManager):
    def __init__(self, canvas: FigureCanvasAgg, num: int = 1):
        super().__init__(canvas, num, MyTermTransport)


class MyTermFigureCanvas(FigureCanvasAgg):
    manager_class = _api.classproperty(lambda _: MyTermFigureManager)


@_Backend.export
class _BackendMyTermAgg(_Backend):
    FigureCanvas = MyTermFigureCanvas
    FigureManager = MyTermFigureManager

    @classmethod
    def draw_if_interactive(cls):
        manager = Gcf.get_active()
        if manager and manager.canvas.figure.get_axes():
            cls.show()

    @classmethod
    def show(cls, *args, **kwargs):
        manager = Gcf.get_active()
        if manager:
            manager.show(*args, **kwargs)
            Gcf.destroy_all()

✅ Step 3: Add It to pyproject.toml

[project.entry-points."matplotlib.backends"]
wskr_myterm = "your_module_path"

✅ Step 4: Use It

import matplotlib
matplotlib.use("wskr_myterm")

import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.show()

Testing

pytest

License

GPL-3.0-only

Metadata

Release files for wskr 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wskr 0.0.3
File Size Uploaded Provenance Actions
wskr-0.0.3.tar.gz 15.6 kB Without provenance Details for wskr-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wskr 0.0.3
File Interpreter ABI Platform Actions
wskr-0.0.3-py3-none-any.whl Python 3 none any Details for wskr-0.0.3-py3-none-any.whl

Total release size: 36.2 kB

Release files / wskr-0.0.3.tar.gz

Download URL wskr-0.0.3.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0b6d224a4bdaa894b22e11a4ef6e7f8e3fe9c25e7df8e0fad060e5327b3a4ab2
BLAKE2b-256 checksum
How to use checksums
dc6bccce2bc598bd473531262fa17d5df40a9ad889859b83b6daf187c52931bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release files / wskr-0.0.3-py3-none-any.whl

Download URL wskr-0.0.3-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8fcabb90c107cb58bb5fbed11c5c66278bbadfc96c42bc1c2b364f13b6e7d654
BLAKE2b-256 checksum
How to use checksums
7080ceddddb7f5206a86fd36f73bb7300410b7c2740609dde2c54bc41e441564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Security for wskr 0.0.3

Provenance

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

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.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page