3

I am looking for a simple tool to visualize the call graph for Python modules (i.e. what function calls what function etc.).

It exists an abandoned package pycallgraph, which does not work anymore.

Is there any other package available to can represent Python call graphs?

5
  • 1
    You probably can do something with doxygen.
    – albert
    Sep 25 '18 at 8:59
  • 1
    It is quite simple. See the comments with your question stackoverflow.com/questions/52494608/…
    – albert
    Sep 25 '18 at 9:36
  • Yes, that is my other post...
    – Alex
    Sep 25 '18 at 9:37
  • But I still have no graphical representation of e.g. where some method is called from...
    – Alex
    Sep 25 '18 at 9:39
  • 1
    I agree, Albert, Doxygen should make this simple, plus give the chance to add a lot more documentation. It is pretty much industry standard in embedded programming . Sep 25 '18 at 12:16
1

You can use pyan.py to generate a call graph. See this stackoverflow question for details.

Usage: pyan.py FILENAME... [--dot|--tgf]

Analyse one or more Python source files and generate an approximate call graph
of the modules, classes and functions within them.

Options:
  -h, --help           show this help message and exit
  --dot                output in GraphViz dot format
  --tgf                output in Trivial Graph Format
  -v, --verbose        verbose output
  -d, --defines        add edges for 'defines' relationships [default]
  -n, --no-defines     do not add edges for 'defines' relationships
  -u, --uses           add edges for 'uses' relationships [default]
  -N, --no-uses        do not add edges for 'uses' relationships
  -c, --colored        color nodes according to namespace [dot only]
  -g, --grouped        group nodes (create subgraphs) according to namespace
                       [dot only]
  -e, --nested-groups  create nested groups (subgraphs) for nested namespaces
                       (implies -g) [dot only]
0

I feel slightly guilty here for just capitalising on @MawgsaysreinstateMonica 's and @albert 's comments, which gives most of the answer, but I thought I'd just formalise it for another reader's benefit.

  1. Install Doxygen.
  2. Install Graphviz, and add its 'bin' directory
  3. Run up Doxywizard, and select the "Call graphs" and "Called by graphs" options (these are unticked by default) [- ee @albert 's link https://stackoverflow.com/questions/52494608/how-to-use-doxygen-to-create-a-documentation-and-call-graphs-for-all-python-fi for the keyword equivalents.

This produces adequate call graphs, although they seem to get confused by Python's

if __main__:
   pass

clause. I just commented it out while producing the diagrams.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.