Skip to main content

ansicolortags brings a simple and powerful way to use colours in a terminal application with Python 2 and 3.

Project description

The ansicolortags module provides efficient and useful functions to use colours in a terminal application with Python 2 and 3, with a HTML-tag like style : <red>text<white> will print text in red.

All ANSI colors code are defined with this tag-like style. This point is the main interest of this module, because all others modules define function to print with some colours.

The complete documentation can be found here : !



You can choose one of the 8 basic ANSI colours: black, red, green, yellow, blue, magenta, cyan, white. The names beginning with a lower-script design foreground colours.

For example:

from ansicolortags import printc
printc('<reset>This is default. <red>This is red<yellow> and yellow in foreground now<reset>').


You can choose one of the 8 basic ANSI colours: Black, Red, Green, Yellow, Blue, Magenta, Cyan, White. The names beginning with an upper-script design background colors.

For example:

from ansicolortags import printc
printc('<Default>this is default. <Blue>this have a blue background<Black> and black in background now<reset>').

Other tags

The following tags are also available:

  • b, B : to turn on and off the bold mode,

  • u, U : to turn on and off the underline mode,

  • neg, Neg : to turn on and off the reverse video mode,

  • blink, Blink : to turn on and off the blink mode,

  • el : to erase the current line,

  • bell : to make the terminal ring.


Some macros are also provided, like the tags <ERROR>, <INFO> or <WARNING>.

And also <warning> and <question>, which respectively give a colored ! and ?.

The reset tag is a special tag to reinitialize all previously changed parameters.

Writing to a file ?

This is possible with the writec function. For example:

import sys
from ansicolortags import writec
writec('<ERROR><u><red>The computer is going to explode!<reset>', fn=sys.stderr)
# sys.stderr.flush()
# this is useless : writec flush itself.

Auto detection

Of course, the colors are disabled if the output does not support them.

It works perfectly on any GNU/Linux (tested with Ubuntu 10+, Debian, Arch Linux) and Windows (with or without Cygwin), and should work fine one MAC OS X or on other UNIX-like.

Other features

Other functions

There is also the xtitle() function, to change the title of the terminal. This try to use the command-line tool xtitle, and if it fails it tries to use an ANSI code to change the title.

There is also a notify() function to display a system notification (using the command-line tool notify-send).

Script is also a script. You can have his description (or use it) directly with:

python -m ansicolortags --help

For testing can be used to run some tests (with the --test option).

With GNU/Bash can be used to generate a GNU/Bash color profile (with the --generate --file options).

See here for this file

This sh file can be imported with $ . in any GNU/Bash scripts, or even in your ~/.bashrc file.

License ?

This module is licensed under the term of the MIT License, see the file LICENSE for more details.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution (19.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page