The pretty library allows developers to add pretty printing rules for their
own objects. This process is straightforward. All you have to do is to
add a _repr_pretty_ method to your object and call the methods on the
pretty printer passed:

classMyObject(object):def_repr_pretty_(self,p,cycle):...

Depending on the python version you want to support you have two
possibilities. The following list shows the python 2.5 version and the
compatibility one.

Here the example implementation of a _repr_pretty_ method for a list
subclass for python 2.5 and higher (python 2.5 requires the with statement
__future__ import):

The cycle parameter is True if pretty detected a cycle. You have to
react to that or the result is an infinite loop. p.text() just adds
non breaking text to the output, p.breakable() either adds a whitespace
or breaks here. If you pass it an argument it’s used instead of the
default space. p.pretty prettyprints another object using the pretty print
method.

The first parameter to the group function specifies the extra indentation
of the next line. In this example the next item will either be not
breaked (if the items are short enough) or aligned with the right edge of
the opening bracked of MyList.

Baseclass for the RepresentationPrinter prettyprinter that is used to
generate pretty reprs of objects. Contrary to the RepresentationPrinter
this printer knows nothing about the default pprinters or the _repr_pretty_
callback method.

Special pretty printer that has a pretty method that calls the pretty
printer for a python object.

This class stores processing data on self so you must never use
this class in a threaded environment. Always lock it or reinstanciate
it.

Instances also have a verbose flag callbacks can access to control their
output. For example the default instance repr prints all attributes and
methods that are not prefixed by an underscore if the printer is in
verbose mode.