Easy CLI colours for Python applications.
Install from PyPI:
pip install colours
from colours import colour print colour.red('I am red!') print colour.blue('I am blue!')
The colour methods take an optional argument of the stream you're passing the output to, in order to determine whether to actually colour the output or not. If the stream is a TTY, the output is coloured. If it isn't (such as a file, or the
sys.stdout is being piped to another program), the output won't be coloured. You can also set this globally.
from colours import colour import sys print colour.red('I am red unless this output is piped to another program', stream=sys.stdout) print colour.blue('I am not blue because my output is a file', stream=open('output.txt', 'w')) # Set the stream globally colour.set_stream(sys.stdout) print colour.green('Now I do not need to worry about passing the stream parameter.')