Diagramming Python Object Graphs

Posted on Wed 06 June 2018 in technology

If you ever want to look at the dependency graph of a python object:

import objgraph
obj = objgraph.by_type('OAG_AutoNode1a')[0]
objgraph.show_backrefs([obj], filename='depgraph.png', max_depth=100)

This will dump the dependency graph for the first OAG_AutoNode1a object into a file depgraph.png.

Useful for finding memory leaks. Requires the objgraph python module and the graphviz (system) package:

pip-3.6 install objgraph --user
pkg install graphviz