> Graphify: shared context of codebase for agents and developers. Canonical: https://graphify.com/blog/how-to-generate-a-call-graph-for-a-python-project · Full index: https://graphify.com/llms-full.txt

# How to generate a call graph for a Python project

*November 5, 2026 · Syed Fahad*

A Python call graph is a map of the functions, methods and modules in a project, with edges for calls, imports and other relationships. You query it to find callers and paths, instead of grepping for a name.

This walkthrough uses the Graphify CLI on a public checkout of [pallets/flask](https://github.com/pallets/flask) at commit `49943b5` (30 October 2026). The same commands work in any Python repository the CLI can parse. For the broader idea of [codebase indexing](https://graphify.com/blog/codebase-indexing-explained), see that explainer.

## How do I generate a call graph for a Python project?

Install the Graphify CLI with `uv tool install --python 3.12 graphifyy`, go to the project root, and run `graphify update .`. The command parses the Python sources with tree-sitter, writes graphify-out/graph.json, and does not call a model.

```bash
uv tool install --python 3.12 graphifyy
git clone https://github.com/pallets/flask.git
cd flask
git checkout 49943b5
graphify update .
```

On this checkout the CLI read 106 files and finished in about 2 seconds. The graph had 2,341 nodes, 3,750 edges and 198 communities. Results vary by codebase.

Every edge carries a provenance tag. EXTRACTED means the relationship was read from the syntax tree. INFERRED means it was resolved by inference rather than read directly. Of the 3,750 edges in this Flask graph, 3,459 were EXTRACTED and 291 were INFERRED. The CLI's code pass never writes AMBIGUOUS. A name with two possible targets gets no edge. When a later query is ambiguous, the CLI lists the candidates and asks you to pick one.

Two SQL files in the repo added nothing, because the optional SQL extra was not installed. That does not change the Python call graph.

## How do I find the callers of a Python function?

After the graph is built, run `graphify affected function_name` in the project root. The CLI walks backward from the symbol and lists importers and callers with file and line. If the name is used in more than one file, it lists the matches and asks you to pick one.

A unique name is the easy case. `url_for` is Flask's helper for building URLs, defined in `src/flask/helpers.py`. Asking for it returns the modules that import it:

```text
graphify affected "url_for"
Affected nodes for url_for()
- flask/__init__.py [imports] src/flask/__init__.py:L22
- wrappers.py [imports_from] src/flask/wrappers.py:L10
- sansio/app.py [imports_from] src/flask/sansio/app.py:L21
- sansio/blueprints.py [imports_from] src/flask/sansio/blueprints.py:L8
- scaffold.py [imports_from] src/flask/sansio/scaffold.py:L17
- flask/views.py [imports_from] src/flask/views.py:L5
```

A shared name needs a second step. `dispatch_request` appears on Flask's app, on `MethodView`, and in tests. The CLI does not guess:

```text
graphify affected "dispatch_request"
Ambiguous: 'dispatch_request' matches 5 nodes in different files.
  src/flask/app.py
  src/flask/views.py
  tests/test_views.py
  tests/test_async.py
  tests/type_check/typing_route.py
Retry with path::symbol using one of the paths above
```

Pick one with `path::symbol`, for example `src/flask/app.py::.dispatch_request()`. That is the same idea as the [blast radius](https://graphify.com/blog/code-change-blast-radius) guide, applied to a real Python tree.

You can also ask for a path between two symbols. On this checkout, `graphify path` from `src/flask/helpers.py::url_for()` to `src/flask/app.py::.url_for()` returned a 4 hop path whose weakest link was still EXTRACTED.

## Can I see a Python call graph in the browser?

Yes. `graphify update .` already writes graphify-out/graph.html. `graphify export callflow-html` adds a second page of Mermaid call-flow diagrams and call tables, which you can open as a local file.

```bash
graphify export callflow-html --output graphify-out/callflow.html
```

On this Flask graph the export finished in under a second and wrote 17 sections, 16 Mermaid diagrams and 15 call tables to `graphify-out/callflow.html`.

## What should I remember when the code changes?

The graph is a snapshot of the checkout you built. After you edit the code, run `graphify update .` again. `graphify hook install` adds git hooks that rebuild after commits, checkouts, merges and rewrites, so the local graph follows the branch you are on.

The Graphify CLI is open source. The [install guide](https://graphify.com/blog/install-graphify) covers setup, [what is a code knowledge graph](https://graphify.com/blog/what-is-a-code-knowledge-graph) explains the map, and the hosted app is at [app.graphify.com](https://app.graphify.com) if you want the same graph for a team.
