Skip to main content

image

image image image image CodSpeed

Chromatic is a library for ANSI art image processing and colored terminal text.

It offers a collection of algorithms and types for a variety of use cases:

  • Image-to-ASCII / Image-to-ANSI conversions.
  • ANSI art rendering, with support for user-defined fonts.
  • A ColorStr type for low-level control over ANSI SGR strings.
  • colorama-style wrappers (Fore, Back, Style).
  • Conversion between 16-color, 256-color, and true-color (RGB) ANSI colorspace via the colorbytes type.
  • Et Cetera 😲

Usage

ColorStr

from chromatic import ColorStr

cs = ColorStr("hello world", fg=0xFF0000, ansi_type="8b")

assert cs.base_str == "hello world"
assert len(cs) == len("hello world")

head, tail = cs.split()

assert head.fg == tail.fg == cs.fg
assert all(c.fg == cs.fg for c in cs)

ColorStr is a str subclass that carries SGR state as metadata. Its str methods delegate to the base string and return ColorStr instances that retain the SGR state.

assert str(cs) == "\x1b[38;5;196mhello world\x1b[0m"
assert cs.ansi == b"\x1b[38;5;196m"

The SGR sequence materializes when the ColorStr is converted back to a Python str.

color_chain

from chromatic import color_chain

cc = color_chain(
    [ColorStr("hello", fg=0xFF0000), ColorStr(" world", fg=0x00FF00)], ansi_type="8b"
)

sgr, s = cc[0]

assert sgr.fg == (0xFF, 0, 0)
assert s == "hello"

A color_chain is a sequence of colored-text fragments that round-trips with a structured NumPy array. Each fragment is an (sgr, text) pair of the SGR state and the run of text it applies to.

cc2 = color_chain("\x1b[38;5;196mhello\x1b[38;5;46m world")

assert cc == cc2

The constructor also parses a raw SGR string. It infers the color depth from the sequence, so cc2 needs no ansi_type.

arr = cc.term_array()

assert arr.dtype == [("char", "<U1"), ("sgr", "<u8"), ("rgb", "u1", (2, 4))]
assert str(color_chain.fromarray(arr)) == str(cc)

term_array exposes the structured ndarray behind the chain, and fromarray reverses it. fromarray accepts any ndarray of that dtype, so an array built by other means converts to a printable color_chain.

img2ansi

from chromatic import img2ansi

cc = img2ansi("input.png")

img2ansi reads an image and returns a color_chain.

arr = img2ansi("input.png", outarray=True)

assert color_chain.fromarray(arr) == cc

outarray=True returns the underlying ndarray instead.

ansi2img

from chromatic import ansi2img

img = ansi2img(cc)
img.show()

ansi2img renders a color_chain back to an image. It also accepts a dtype-matching array.

ansify

from chromatic import ansify

img = ansify("input.png")
arr = img.info["ansi_array"]

ansify runs both directions in one call, returning the rendered image with the array it rendered from on Image.info.

Animated images

frames = img2ansi("input.gif")

assert isinstance(frames, list)
assert all(isinstance(f, color_chain) for f in frames)

An animated image renders to a list[color_chain], one per frame.

chromatic image ansify input.gif --stdout

The CLI renders and plays one straight to the terminal.

Installation

Install the package using pip:

pip install chromatic-python

Credits

Banner artwork: main rules by Crasher (2002)

Metadata

Release files for chromatic-python 0.9.2

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

Source distribution (sdist)

Source distribution for chromatic-python 0.9.2
File Size Uploaded Provenance Actions
chromatic_python-0.9.2.tar.gz 342.5 kB With provenance Details for chromatic_python-0.9.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chromatic-python 0.9.2
File Interpreter ABI Platform Actions
chromatic_python-0.9.2-py3-none-any.whl Python 3 none any Details for chromatic_python-0.9.2-py3-none-any.whl

Total release size: 427.3 kB

Release files / chromatic_python-0.9.2.tar.gz

Download URL chromatic_python-0.9.2.tar.gz
Size 342.5 kB
Tags Source
SHA-256 checksum
How to use checksums
acb9121a09487cef61caa3302109d3d1883314969f23642a62bc3491e5d93f70
BLAKE2b-256 checksum
How to use checksums
6363ef936af5ad5ce0b21b3a9fe127fb0ab96258f2897c82b3596ad4fc572cd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.

Transparency log

Release files / chromatic_python-0.9.2-py3-none-any.whl

Download URL chromatic_python-0.9.2-py3-none-any.whl
Size 84.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2671c36ea6d93f15f5dea0f4b7fbfa64d3aaa233fc6c80c6cac6d404fb6cb41
BLAKE2b-256 checksum
How to use checksums
a86ed61f3b7e9dd4f7d2e1d00b84fbdf8e1a9172fac39c099128a49bbedcadf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.

Transparency log

Security for chromatic-python 0.9.2

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for chromatic_python-0.9.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 19, 2026.

Transparency log

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.9.2 This release

2 release files Full 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