ANSI color formatting for output in terminal
Maintained. Last release 11 months ago, commits in 11 of the last 26 weeks. Weaker on release cadence and contributor spread.
pip install termcolortermcolor
Installation
From PyPI
python3 -m pip install --upgrade termcolor
From source
git clone https://github.com/termcolor/termcolor
cd termcolor
python3 -m pip install .
Demo
To see demo output, run:
python3 -m termcolor
Example
import sys
from termcolor import colored, cprint
text = colored("Hello, World!", "red", attrs=["reverse", "blink"])
print(text)
cprint("Hello, World!", "green", "on_red")
print_red_on_cyan = lambda x: cprint(x, "red", "on_cyan")
print_red_on_cyan("Hello, World!")
print_red_on_cyan("Hello, Universe!")
for i in range(10):
cprint(i, "magenta", end=" ")
cprint("Attention!", "red", attrs=["bold"], file=sys.stderr)
# You can also specify 0-255 RGB ints via a tuple
cprint("Both foreground and background can use tuples", (100, 150, 250), (50, 60, 70))