talira

Colorama

Cross-platform coloured terminal text in Python

open sourceBSD-3-Clausefree

Colorama is a Python library that makes ANSI escape sequences for coloured text and cursor positioning work on Windows. It wraps stdout, strips the ANSI sequences it finds and turns them into the matching Win32 console calls; on other platforms it does nothing. That gives a simple cross-platform API for printing coloured text, and lets existing programs that print ANSI colours on Linux and macOS work on Windows by calling just_fix_windows_console() or init(). It needs nothing beyond the standard library.

Problems it solves

  • make my Python script's coloured output show properly on Windows
  • print coloured terminal text from Python that works on every platform
  • stop ANSI escape codes appearing as garbage in the Windows command prompt

Features

  • Makes ANSI colour and cursor sequences work in the Windows console
  • just_fix_windows_console() fixes existing ANSI output with one call
  • Fore, Back and Style constants for coloured text
  • Does nothing on platforms that already handle ANSI
  • No dependencies beyond the standard library

Limitations

  • On Windows it doesn't support ANSI dim text, which looks the same as normal text1

Alternatives

The same job

These do what Colorama does.

  1. go-colorable Colorable writer for Windows
  2. termcolor ANSI colour formatting for terminal output in Python
  3. Rich Rich text and beautiful formatting in the terminal for Python

Compare Colorama with the top 3