Expand description
Python dependency extractor using tree-sitter queries.
Extracts import and from ... import statements from Python source files,
producing ImportInfo records for the dependency graph. Supports:
- Absolute imports:
import os,import os.path - From imports:
from os import path,from os.path import join, exists - Relative imports:
from .utils import helper,from ..core import Engine - Wildcard imports:
from module import * - Aliased imports:
import numpy as np,from os import path as ospath
§Examples
ⓘ
use thread_flow::incremental::extractors::python::PythonDependencyExtractor;
use std::path::Path;
let extractor = PythonDependencyExtractor::new();
let source = "import os\nfrom pathlib import Path";
let imports = extractor.extract_imports(source, Path::new("main.py")).unwrap();
assert_eq!(imports.len(), 2);§Performance
Target: <5ms per file extraction. Tree-sitter parses the full AST and a single recursive walk collects all import nodes, avoiding repeated traversals.
Structs§
- Import
Info - Information extracted from a single Python import statement.
- Python
Dependency Extractor - Extracts Python import dependencies using tree-sitter AST walking.
Enums§
- Extraction
Error - Errors that can occur during import extraction.