Using pyreverse to generate UML class diagrams

Recently I wanted to generate UML (Unified Modeling Language) diagrams of the structure of an existing codebase for the purpose of having an architecture discussion.

I was wondering if there was a tool to generate UML diagrams in Python to save me some manual work.

Enter pyreverse: it comes installed with pylint which is a very common development dependency in Python. pyreverse enables you to point to the code you want UML diagrams of, here in my example I was generating a diagram of a project called securedrop-export:

pyreverse securedrop_export/

This produces in the same directory a graphviz file called classes.dot.

Then, provided you have graphviz (which provides the dot command) installed:

dot -Tpng classes.dot -o securedrop_export.png

Which produces the following:

securedrop-export

Here ExportStatus is an Enum and TimeoutException is a custom exception (in red).