Analyzer
analyzer
High-level package analysis engine.
This module builds on the tree-sitter parser to provide package-wide analysis: module discovery, dependency graphs, public API extraction, and semantic search.
Example
from pathlib import Path from axm_ast.core.analyzer import analyze_package pkg = analyze_package(Path("src/mylib")) [m.path.name for m in pkg.modules]['__init__.py', 'core.py', 'utils.py']
analyze_package(path)
Analyze a Python package directory.
Discovers all .py files, parses them with tree-sitter, and
builds a complete PackageInfo with dependency edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the package root directory. |
required |
Returns:
| Type | Description |
|---|---|
PackageInfo
|
PackageInfo with all modules and dependency edges. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If path is not a directory. |
Example
pkg = analyze_package(Path("src/mylib")) pkg.name 'mylib'
Source code in packages/axm-ast/src/axm_ast/core/analyzer.py
build_import_graph(pkg)
Build an adjacency-list import graph from package info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Dict mapping module name to list of modules it imports. |
Example
graph = build_import_graph(pkg) graph["cli"]['core', 'models']
Source code in packages/axm-ast/src/axm_ast/core/analyzer.py
find_module_for_symbol(pkg, symbol)
Find the module containing a symbol.
Supports two lookup modes:
- Object (
FunctionInfo/ClassInfo): identity-first match, then name fallback. - String: name-based search across functions, methods, and classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
symbol
|
str | FunctionInfo | ClassInfo | VariableInfo
|
Symbol name or object to locate. |
required |
Returns:
| Type | Description |
|---|---|
ModuleInfo | None
|
The |
Source code in packages/axm-ast/src/axm_ast/core/analyzer.py
get_public_api(pkg)
Extract the public API surface of a package.
Uses __all__ when available, otherwise filters by name convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
Returns:
| Type | Description |
|---|---|
list[FunctionInfo | ClassInfo]
|
List of public functions and classes. |
Example
api = get_public_api(pkg) [a.name for a in api]['main', 'Config']
Source code in packages/axm-ast/src/axm_ast/core/analyzer.py
module_dotted_name(mod_path, root)
Convert a module file path to a dotted name relative to root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mod_path
|
Path
|
Absolute path to a |
required |
root
|
Path
|
Package root directory. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Dotted module name (e.g. |
Source code in packages/axm-ast/src/axm_ast/core/analyzer.py
search_symbols(pkg, *, name=None, returns=None, kind=None, inherits=None)
Search for symbols across a package with filters.
All filters are AND-combined. A symbol must match all provided filters to be included in results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
name
|
str | None
|
Filter by symbol name (substring match). |
None
|
returns
|
str | None
|
Filter functions by return type (substring match). |
None
|
kind
|
SymbolKind | None
|
Filter by SymbolKind (function, method, property, classmethod, staticmethod, abstract, class, variable). |
None
|
inherits
|
str | None
|
Filter classes by base class name. |
None
|
Returns:
| Type | Description |
|---|---|
list[FunctionInfo | ClassInfo | VariableInfo]
|
List of matching symbols. |
Example
results = search_symbols(pkg, returns="str") [r.name for r in results]['greet', 'version']