CodeGraph
provides two methods to analyze and navigate code relationships: init
and enrich
.
init
path
: Path to directory (e.g., .
, ./src/my_package
, absolute path)timeout_seconds
: Timeout threshold in seconds. Defaults to 60.CodeGraphResult
containing:
code_graph
: Successful CodeGraph
instanceerrors
: List of initialization errors (if any).nuanced
directory for analysis resultsFileNotFoundError
: Directory not foundValueError
: No Python files in directoryTimeoutError
: Initialization exceeds default timeout of 60 secondsinit
command analyzes the Python files in the specified directory, creates a .nuanced
directory to store analysis results where the full call graph is written to a file called nuanced-graph.json
, and returns a CodeGraphResult
with either the graph or any errors encountered.
enrich
enrich
command takes a file path and function name, and returns an EnrichmentResult
containing the function’s call graph when found, and any errors encountered (e.g., ValueError
when multiple matching functions exist). Unlike the result of init
, which is written to a file, the result of enrich
is held in memory.
When infer_arg_types
is True
, function argument type inference is performed and inferred types are included in the args
property of function nodes.
When include_builtins
is True
, edges to Python’s builtins
functions are included.
Parameters:
file_path
: Path to the file containing the functionfunction_name
: Fully qualified function name (e.g., package.submodule.function
)filepath
: Path to the source filecallees
: List of fully qualified function names called by this functionValueError
: Multiple function definitions foundcallees
are prefixed with <builtin>.
app.helpers.format_data
) based on the file’s location and module structure.nuanced enrich
command or CodeGraph#enrich
method have the following attributes:
Name | Type | Description | Empty if | Free | Paid |
---|---|---|---|---|---|
callees | list[str] | A list of fully qualified function names uniquely identifying functions that are invoked by the function or alias the function | Function has no callees | Yes | Yes |
callers | list[str] | A list of fully qualified function names uniquely identifying functions that invoke the function | Function has no callers | No | Yes |
filepath | str | The absolute path to the file where the function is defined | N/A | Yes | Yes |
lineno | int | The starting line number of the function or module’s definition | N/A | Yes | Yes |
end_lineno | int | The ending line number of the function or module’s definition | N/A | Yes | Yes |
inferred_return_types | list[str] | The function’s return types derived from the function’s return type hint or inferred from the contents of the file in which the function is defined | Inference fails or source code indexed by init is unavailable at the time enrich is executed | No | Yes |
args | dict | The function’s arguments’ names and inferred types derived from the function’s argument type hints or inferred from the contents of the file in which the function is defined | Inference fails or source code indexed by init is unavailable at the time enrich is executed | No | Yes |
signature | str | The function’s signature | Source code indexed by init is unavailable at the time enrich is executed | No | Yes |
inferred_return_types
and inferred_types
graph attributes include annotated as well as inferred types.
The scope of analysis is currently limited as follows:
*args
and **kwargs
init
and enrich
commandsdocstring
: Function documentation if availablelines_of_code
: Total lines of code in the functionnumber_of_parameters
: Number of parameters the function acceptscyclomatic_complexity
: Measure of function complexitylogical_lines_of_code
: Number of executable statements.nuanced
directories that you can safely check into version control. This makes it easy to share insights with your team and track how Python code in your codebase evolves over time. This approach allows developers to: