This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: utils.PyColorize

Class and program to colorize python source code for ANSI terminals.

Based on an HTML code highlighter by Jurgen Hermann found at:

Modifications by Fernando Perez (

Information on the original HTML highlighter follows:

MoinMoin - Python Source Parser

Title: Colorize Python source using the built-in tokenizer

Submitter: Jurgen Hermann Last Updated:2001/04/06

Version no:1.2


This code is part of MoinMoin ( and converts Python source code to HTML markup, rendering comments, keywords, operators, numeric and string literals in different colors.

It shows how to use the built-in keyword, token and tokenize modules to scan Python source code and re-emit it with no changes to its original formatting (which is the hard part).

1 Class

class IPython.utils.PyColorize.Parser(color_table=None, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, parent=None, style=None)

Bases: IPython.utils.colorable.Colorable

Format colored Python source.

__init__(color_table=None, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, parent=None, style=None)

Create a parser with a specified color table and output channel.

Call format() to process code.

format2(raw, out=None)

Parse and send the colored source.

If out and scheme are not specified, the defaults (given to constructor) are used.

out should be a file-type object. Optionally, out can be given as the string ‘str’ and the parser will automatically return the output in a string.