Visualize the structure of a Python module

Question:

Is there tool out there which can be used to graphically represent the structure of a python module?

I’m thinking that a graph of sub-modules and classes connected by arrows representing imports.

Asked By: alex

||

Answers:

Not sure if there’s a tool, but you could always parse the package you’re working with, walking the directory subtree and recording the classes for each module, and also recording the imports. (If you’re working with a single module, then it’d just be checking the classes and inputs, no path-walking required.) Then you’d have to iteratively or recursively (Python recommends iteration) check each module imported for anything imported by them until there are no more imports to make (be careful about circular imports!).

You’ll probably find pydot or something similar quite useful for graphically displaying the structure.

Answered By: JAB

I think you want the Python library snakefood

sfood:
Given a set of input files or root directories, generate a list of dependencies between the files;

sfood-graph:
Read a list of dependencies and produce a Graphviz dot file. (This file can be run through the Graphviz dot tool to produce a viewable/printable PDF file);

Answered By: user626998

An IDE for Python, called ERIC used to have this very functionality

Answered By: Ilia Gilmijarow

I know this question is very old. If someone is searching a tool for visualising the structure of a Python module, you can try Sourcetrail.

This tool helps you to visualise big source codes such as PyTorch or TensorFlow.

It starts with a nice overview of the project.

enter image description here

If you go inside the Classes button and select any class, it will show you the connection of a specific class with other classes and functions.

enter image description here

All the buttons are clickable and gives you a nice overview. This gives you a kickstart to understand the structure of unknown source code very easily.

Answered By: Prakhar Sharma
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.