I just described very popular library clint. Which has more features apart of coloring the output on terminal.
By the way it support MAC, Linux and Windows terminals.
Here is the example of using it:
Installing (in Ubuntu)
pip install clint
To add color to some string
colored.red('red string')
Example: Using for color output (django command style)
from django.core.management.base import BaseCommand
from clint.textui import colored
class Command(BaseCommand):
args = ''
help = 'Starting my own django long process. Use ' + colored.red('<Ctrl>+c') + ' to break.'
def handle(self, *args, **options):
self.stdout.write('Starting the process (Use ' + colored.red('<Ctrl>+c') + ' to break)..')
# ... Rest of my command code ...