exporter.CodeGenerator
Generates Python code from Excel formulas.
Usage
exporter.CodeGenerator()Methods
| Name | Description |
|---|---|
| __init__() | Initialize the code generator. |
| derive_input_series() | Derive input-series metadata from explicit series bindings. |
| generate() | Generate standalone Python code for target cells. |
| generate_modules() | Generate a multi-module Python package for target cells. |
__init__()
Initialize the code generator.
Usage
__init__(
graph, *, iterate_enabled=None, iterate_count=100, iterate_delta=0.001
)Parameters
graph: DependencyGraph | GraphLike-
Dependency graph from excel_grapher containing cell formulas.
iterate_enabled: bool | None = None-
If True, DependencyGraph.evaluation_order rejects any must- or may-cycle (workbook iterative calc is unsupported in codegen). Typically set from excel_grapher.get_calc_settings.
Noneskips this check (default). iterate_count: int = 100-
Maximum iterations when iterative calculation is enabled.
iterate_delta: float = 0.001- Convergence threshold when iterative calculation is enabled.
derive_input_series()
Derive input-series metadata from explicit series bindings.
Usage
derive_input_series(bindings, *, workbook)generate()
Generate standalone Python code for target cells.
Usage
generate(
targets=None,
*,
constant_types=None,
constant_ranges=None,
constant_blanks=False,
input_ranges=None,
blank_ranges=None,
series_bindings=None,
bindings_workbook=None,
series_docstring_callback=None,
docstring_renderer="google"
)Parameters
targets: Sequence[str] | None = None-
List of target cell addresses to compute.
constant_types: set[str] | None = None-
Cell value kinds emitted as typed constants in generated code.
constant_ranges: Sequence[str] | None = None-
Sheet-qualified ranges whose cells are emitted as constants.
constant_blanks: bool = False-
When True, blank cells in constant ranges become
None. input_ranges: Sequence[str] | None = None-
Sheet-qualified ranges whose leaf cells are treated as inputs. When a cell would otherwise be a constant,
input_rangestake precedence. blank_ranges: Sequence[str] | None = None-
Sheet-qualified rectangles whose cells are omitted from the graph but resolve as empty (
None) at runtime; must match builder/evaluator. series_bindings: WorkbookSeriesBindings | None = None-
Optional workbook binding manifest; when set with
bindings_workbook, emitsset_*functions that accept Records. bindings_workbook: Path | str | None = None-
Path to the
.xlsxfile used to resolve binds. series_docstring_callback: SeriesBindingDocstringCallbackSpec | None = None-
Optional registered callback name for structured docstrings on generated
set_*and series outputcompute_*functions. docstring_renderer: SeriesDocstringRendererSpec = "google"-
Built-in renderer name or custom renderer object/callable for structured series-binding docstrings (
plain,rst,google,numpy).
Returns
str- Standalone Python source code as a string.
generate_modules()
Generate a multi-module Python package for target cells.
Usage
generate_modules(
targets=None,
*,
constant_types=None,
constant_ranges=None,
constant_blanks=False,
input_ranges=None,
blank_ranges=None,
series_bindings=None,
bindings_workbook=None,
series_docstring_callback=None,
docstring_renderer="google"
)Returns a mapping of module filenames to file contents. Callers choose how to lay out files on disk (e.g. a package directory).
The generated package has five flat files: - init.py: exports compute_all and DEFAULT_INPUTS - api.py: compute_all, make_context, and series-binding set_* / compute_* functions - data.py: DEFAULT_INPUTS and CONSTANTS - runtime.py: embedded Excel runtime (emit_runtime) - internals.py: formula cell functions + resolver dispatch