pympler.refgraph

This module exposes utilities to illustrate objects and their references as (directed) graphs. The current implementation requires ‘graphviz’ to be installed.

Classes

class pympler.refgraph.ReferenceGraph(objects, reduce=False)

The ReferenceGraph illustrates the references between a collection of objects by rendering a directed graph. That requires that ‘graphviz’ is installed.

>>> from pympler.refgraph import ReferenceGraph
>>> a = 42
>>> b = 'spam'
>>> c = {a: b}
>>> gb = ReferenceGraph([a,b,c])
>>> gb.render('spam.eps')
True
__init__(objects, reduce=False)

Initialize the ReferenceGraph with a collection of objects.

render(filename, cmd='dot', format='ps', unflatten=False)

Render the graph to filename using graphviz. The graphviz invocation command may be overridden by specifying cmd. The format may be any specifier recognized by the graph renderer (‘-Txxx’ command). The graph can be preprocessed by the unflatten tool if the unflatten parameter is True. If there are no objects to illustrate, the method does not invoke graphviz and returns False. If the renderer returns successfully (return code 0), True is returned.

An OSError is raised if the graphviz tool cannot be found.

split()

Split the graph into sub-graphs. Only connected objects belong to the same graph. split yields copies of the Graph object. Shallow copies are used that only replicate the meta-information, but share the same object list self.objects.

>>> from pympler.refgraph import ReferenceGraph
>>> a = 42
>>> b = 'spam'
>>> c = {a: b}
>>> t = (1,2,3)
>>> rg = ReferenceGraph([a,b,c,t])
>>> for subgraph in rg.split():
...   print (subgraph.index)
0
1
write_graph(filename)

Write raw graph data which can be post-processed using graphviz.