The following minimal working example
from pycallgraph2 import PyCallGraph
from pycallgraph2.output import GraphvizOutput
with PyCallGraph(output=GraphvizOutput()):
None
produces this output:
Why does PyCallGraph2 describe itself while profiling "Hello, World"? showed that we can exclude certain things in the namespace via the command line. Now I want to do this inside a script.

I found an answer while I formulating the question. The older documentation for
pycallgraphshows how to filter. If we make some necessary changes such as referring topycallgraph2instead ofpycallgraph, we have:This gives the desired result: