Skip to main content

🎨 cobra-color 🎨
Turn a Plain Terminal into an Expressive Visual Canvas

PyPI version Python codecov License

Tests Github stars

About

cobra-color is a lightweight, easy-to-use Python library for enhanced terminal output, combining string-friendly color styling with one-step ANSI image rendering.

  • Python: 3.9+

Features

  • 🚀 Strong compatibility with native Python strings: Keep familiar str workflows while preserving color/style through operations like concatenation and transformations.
  • 🚀 Full terminal rendering toolkit: Supports both styled text output and image-to-ANSI conversion across multiple modes (such as ascii, half-color, and gray).
  • 🚀 Lightweight and developer-friendly: Minimal core dependencies, optional render extras, and safe_print support for tqdm/rich-friendly console output.

Installation

Install from PyPI

This installs the core package with minimal dependencies.

pip install cobra-color

Install with Optional Dependencies

cobra.render module support.

pip install cobra-color[render]

Quick Start

  • Render a text in the terminal:

    from cobra_color import cstr, safe_print
    
    c_text_1 = cstr("Hello World!", fg="r", styles=["bold"])
    # Print directly from the terminal
    print(c_text_1)
    
    c_text_2 = cstr("Hello World!", fg=(255, 255, 255), styles=["udl", "bold"])
    # Alternatively, you can use safe_print() to automatically support progress bar modes like tqdm and rich.
    safe_print(c_text_2)
    
    # Merge `c_text_1` and `c_text_2` while preserving their colors and style formatting.
    c_text_3 = c_text_1 + c_text_2
    
    # You can continue to use str's proprietary functions and keep the existing colors and styles.
    c_text_1.upper()
    
  • Render an image in the terminal:

    from cobra_color.render import imgfile_to_ansi, safe_print
    
    # ASCII art
    safe_print(imgfile_to_ansi("example.jpg", width=80, mode="ascii"))
    
    # Half-block color (recommended for truecolor terminals)
    imgfile_to_ansi("example.jpg", width=80, mode="half-color", display=True)
    
  • Render some text with fonts in the terminal:

    from cobra_color.draw import fonttext_to_ansi, FontName, safe_print
    
    # Borderless grayscale font
    safe_print(fonttext_to_ansi(
        "Hello World!",
        font=FontName.LLDISCO,
        mode="half-gray",
        trim_border=True
    ))
    

Image Modes

  • ascii: monochrome ASCII using a density charset.
  • color: colorized character fill.
  • half-color: half-block characters with color (higher density, good visual quality).
  • gray: grayscale characters.
  • half-gray: half-block grayscale.

Tip: For best results, use a TrueColor-capable terminal and a monospaced font.

Requirements

  • Python >= 3.9
  • (Optional) Pillow >= 9.0, < 11.0
  • (Optional) NumPy >= 1.21, < 2.0

License

See LICENSE in the repository.

Metadata

Release files for cobra-color 1.3.13

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

Source distribution (sdist)

Source distribution for cobra-color 1.3.13
File Size Uploaded Provenance Actions
cobra_color-1.3.13.tar.gz 32.2 kB Without provenance Details for cobra_color-1.3.13.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cobra-color 1.3.13
File Interpreter ABI Platform Actions
cobra_color-1.3.13-py3-none-any.whl Python 3 none any Details for cobra_color-1.3.13-py3-none-any.whl

Total release size: 66.0 kB

Release files / cobra_color-1.3.13.tar.gz

Download URL cobra_color-1.3.13.tar.gz
Size 32.2 kB
Tags Source
SHA-256 checksum
How to use checksums
18e0491949664fa2891b149b373baf2ee7519add7bd036dfc3b43064336d4dc4
BLAKE2b-256 checksum
How to use checksums
e1abd5b99b44a1981f15643fdc36bb7f7e2e56c558ac7ab9a76337a594949733
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / cobra_color-1.3.13-py3-none-any.whl

Download URL cobra_color-1.3.13-py3-none-any.whl
Size 33.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f10dfd659fb6bee3a997673e12110159b44398e8309b686693176fb62782113c
BLAKE2b-256 checksum
How to use checksums
c227d91516e50902286ec87235435d4268891ad68d5fe8ba04d99e9a98b374cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Security for cobra-color 1.3.13

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

1.3.13 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