Documentation Index¶
Python Call Graph¶
Welcome! Python Call Graph is a Python module that creates call graph visualizations for Python applications.
This repo used to be pycallgraph which is still hosted at pypi link.
The uploader makes no representations of their contribution, and merely wanted this to work in python 3.5; with a goal to porting it to 3.11, 3.12, 3.13 and 3.14
[! NOTE] Please give more ideas for problems or further use-cases for this repo. I am really glad folks like it, but it’s mostly the original author work, and I don’t yet know what more to add to this.
Screenshots¶
Click on the images below to see a larger version and the source code that generated them.
Project Status¶
The latest version is 2.1.6 which was released on 2025-06-06. The latest version has been tested running on Python versions 3.8 - 3.14
The project lives on GitHub, where you can report issues, contribute to the project by forking the project then creating a pull request, or just browse the source code.
The documentation needs some work stiil. Feel free to contribute :smile:
Features¶
Support for Python 3.8 - 3.14.
Static visualizations of the call graph using various tools such as Graphviz and Gephi.
Execute pycallgraph from the command line or import it in your code.
Customisable colors. You can programatically set the colors based on number of calls, time taken, memory usage, etc.
Modules can be visually grouped together.
Easily extendable to create your own output formats.
Quick Start¶
Installation is easy as
pip install python-call-graph
You can either use the command-line interface for a quick visualization of your Python script, or the pycallgraph module for more fine-grained settings.
The following examples specify graphviz as the outputter, so it’s required to be installed. They will generate a file called pycallgraph.png.
The command-line method of running pycallgraph is¶
pycallgraph graphviz -- ./mypythonscript.py
A simple use of the API is¶
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
with PyCallGraph(output=GraphvizOutput()):
code_to_profile()
Documentation¶
Feel free to browse the documentation of pycallgraph for the usage guide and API reference.
Contributing and maintenance¶
Everything a maintainer needs is in one place so the workflow does not depend on tribal knowledge:
Run the tests (Python 3.8 - 3.14):
pip install -r requirements/development.txt PYTHONPATH=$(pwd) pytest --ignore=pycallgraph/memory_profiler.py test pycallgraph examples
The Graphviz tests need the
dotbinary (apt install graphviz/brew install graphviz).test/test_packaging.pybuilds a real sdist.Lint, matching CI:
flake8 --exclude=__init__.py,memory_profiler.py pycallgraph flake8 --ignore=F403 test flake8 examples
Build and release:
python setup.py sdistproduces the distribution; publishing happens automatically from a published GitHub release (.github/workflows/release.yml). The version lives only inpycallgraph/metadata.py.Add an output format by subclassing
pycallgraph.output.Output, implementingdone()(and optionallygenerate()), then registering it in theoutputtersmap inpycallgraph/output/__init__.py. The JSON output is a small, self-contained example.Document new behaviour in
docs/; the man page is generated fromdocs/guide/command_line_usage.rst.