Flows
flows
Execution flow tracing via entry point detection and BFS call graph.
Detects framework-specific entry points (cyclopts, click, Flask, FastAPI,
pytest, __main__ guards) and traces execution flows through the
call graph using BFS.
Example::
>>> from axm_ast.core.analyzer import analyze_package
>>> from axm_ast.core.flows import find_entry_points, trace_flow
>>> pkg = analyze_package(Path("src/mylib"))
>>> entries = find_entry_points(pkg)
>>> for e in entries:
... print(f"{e.framework}: {e.name} ({e.module}:{e.line})")
EntryPoint
Bases: BaseModel
A detected entry point in the codebase.
Source code in packages/axm-ast/src/axm_ast/core/flows.py
| Python | |
|---|---|
FlowStep
Bases: BaseModel
A single step in a traced execution flow.
Source code in packages/axm-ast/src/axm_ast/core/flows.py
TraceKwargs
Bases: TypedDict
Keyword arguments forwarded to :func:trace_flow.
Public mirror of the kwargs accepted by :func:trace_flow so call sites
(notably :mod:axm_ast.hooks.flows) can build typed kwargs dicts without
redefining the contract locally.
Source code in packages/axm-ast/src/axm_ast/core/flows.py
build_callee_index(pkg)
Pre-compute a callee index for the entire package in one pass.
Instead of scanning all modules per symbol (O(modules x AST) per BFS step),
this builds a {(module, symbol): [CallSite]} dict in a single pass.
BFS then uses O(1) dict lookups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
Returns:
| Type | Description |
|---|---|
dict[tuple[str, str], list[CallSite]]
|
Dict mapping |
Source code in packages/axm-ast/src/axm_ast/core/flows.py
find_callees(pkg, symbol, *, _parse_cache=None)
Find all functions called by a given symbol (forward call graph).
This is the inverse of find_callers: instead of asking "who calls X?",
it asks "what does X call?".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
symbol
|
str
|
Name of the function/method to inspect. |
required |
_parse_cache
|
dict[str, tuple[Tree, str]] | None
|
Optional cache of |
None
|
Returns:
| Type | Description |
|---|---|
list[CallSite]
|
List of CallSite objects for each call made by the symbol. |
Example
callees = find_callees(pkg, "main") for c in callees: ... print(f" calls {c.symbol} at {c.module}:{c.line}")
Source code in packages/axm-ast/src/axm_ast/core/flows.py
find_callees_workspace(ws, symbol)
Find all callees of a symbol across a workspace.
Searches every package in the workspace for callees of the
given symbol. Module names are prefixed with pkg_name::
for disambiguation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ws
|
WorkspaceInfo
|
Analyzed workspace info. |
required |
symbol
|
str
|
Name of the function/method to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list[CallSite]
|
List of CallSite objects for each call made by the symbol. |
Source code in packages/axm-ast/src/axm_ast/core/flows.py
find_entry_points(pkg)
Detect framework-registered entry points across a package.
Scans for:
- Decorator-based: cyclopts, click, Flask, FastAPI
- Test functions:
test_*prefix - Main guards:
if __name__ == "__main__"blocks __all__exports
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
Returns:
| Type | Description |
|---|---|
list[EntryPoint]
|
List of EntryPoint objects sorted by module then line. |
Source code in packages/axm-ast/src/axm_ast/core/flows.py
format_flow_compact(steps)
Format flow steps as a compact tree with box-drawing characters.
Each step is rendered on one line. Depth-0 is the root (no prefix), deeper levels use box-drawing connectors with indentation proportional to depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
list[FlowStep]
|
Ordered list of FlowSteps (BFS order, ascending depth). |
required |
Returns:
| Type | Description |
|---|---|
str
|
Tree-formatted string. Empty string when steps is empty. |
Source code in packages/axm-ast/src/axm_ast/core/flows.py
format_flows(entry_points)
Format entry point results as human-readable grouped output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_points
|
list[EntryPoint]
|
List of detected entry points. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Formatted string grouped by framework. |
Source code in packages/axm-ast/src/axm_ast/core/flows.py
trace_flow(pkg, entry, *, max_depth=5, cross_module=False, detail='trace', callee_index=None, exclude_stdlib=True)
Trace execution flow from an entry point via BFS.
Follows the forward call graph from entry up to max_depth levels deep. Uses a visited set to handle circular calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
entry
|
str
|
Name of the entry point function to trace from. |
required |
max_depth
|
int
|
Maximum BFS depth (default 5). |
5
|
cross_module
|
bool
|
If True, resolve imports and continue BFS into external modules on-demand. |
False
|
detail
|
str
|
Level of detail — |
'trace'
|
callee_index
|
dict[tuple[str, str], list[CallSite]] | None
|
Optional pre-computed index from
:func: |
None
|
exclude_stdlib
|
bool
|
If True (default), skip callees whose name
matches a stdlib module or Python builtin (e.g. |
True
|
Returns:
| Type | Description |
|---|---|
list[FlowStep]
|
Tuple of (steps, truncated) where steps is a list of FlowStep |
bool
|
objects ordered by depth then discovery, and truncated is True |
tuple[list[FlowStep], bool]
|
when at least one frontier node at max_depth had unexpanded |
tuple[list[FlowStep], bool]
|
children. |
Example
steps, truncated = trace_flow(pkg, "main", max_depth=3) for s in steps: ... print(f"{' ' * s.depth}{s.name} ({s.module}:{s.line})")
Source code in packages/axm-ast/src/axm_ast/core/flows.py
| Python | |
|---|---|
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 | |