linexcel.result¶
linexcel.result ¶
High-level API, usable as a library (marimo, Jupyter, scripts).
Minimal example, without backend or AI key:
from linexcel import analyze
result = analyze("my_workbook.xlsx")
result # interactive graph in marimo
result.save_html("out.html")
print(result.stats)
AI documentation is optional — pick a provider explicitly (no default):
result.document(base_url="http://localhost:11434/v1", model="llama3.1")
LineageResult ¶
Analysis result: deterministic graph + computation engine + renderers.
The object is directly displayable in a notebook (_repr_html_) and
exposes the JSON graph, convenience accessors, standalone HTML export,
and optional AI documentation.
Source code in src/linexcel/result.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | |
workbook_context
property
¶
Bounded sheet previews, comments, and layout markers.
Context is extracted with openpyxl only; Excel or LibreOffice is
not launched. It deliberately preserves first rows and columns rather
than assuming a tabular header convention.
token_usage
property
¶
Tokens consumed by every :meth:document / :meth:document_workbook
call made on this result.
Counts come from the provider when it reports them (an
OpenAI-compatible endpoint fills in a usage block); otherwise they
are approximated and :attr:TokenUsage.estimated is set. Zero until an
AI call is made.
>>> result.document(provider=my_llm) # doctest: +SKIP
>>> print(result.token_usage) # doctest: +SKIP
~12,480 tokens (~11,120 in + ~1,360 out) over 4 request(s)
node ¶
find ¶
Nodes whose label or formula contains text (case-insensitive)
Source code in src/linexcel/result.py
precedents ¶
Nodes that feed into node_id
dependents ¶
save_screenshots ¶
save_screenshots(output_dir: str | Path, *, dpi: int = 144, timeout: int = 180, per_sheet: bool = True) -> dict[str, list[Path]] | list[Path]
Render the workbook to PNG using LibreOffice headless.
Works on Linux, macOS and Windows. The optional renderer requires
LibreOffice and pdftoppm from Poppler; both are found on PATH or
in their standard install directory, since the Windows and macOS
installers do not extend PATH. Use :attr:workbook_context when
only the non-rendered context is needed.
By default each sheet is rendered whole, onto one image, and the result
is a {sheet name: [png]} mapping — the shape :meth:to_html shows
under each sheet in its Sheets tab:
>>> result.save_html( # doctest: +SKIP
... "report.html",
... screenshots=result.save_screenshots("shots/"),
... )
per_sheet=False returns the flat list[Path] of print pages
instead, laid out by the workbook's own page setup; the report then
shows them in a separate tab, since no page can be tied to a sheet.
A mapping is also downgraded to that flat list when the renderer does
not produce exactly one page per sheet, rather than filing images under
sheets they may not belong to.
Source code in src/linexcel/result.py
document ¶
document(node_ids: list[str] | None = None, *, api_key: str | None = None, model: str | None = None, base_url: str | None = None, provider: ProviderLike | None = None, language: str = 'en', max_workers: int = 4, max_tokens: int | None = None, token_budget: int | None = None) -> dict[str, str]
Document nodes via AI from the deterministic lineage.
Without node_ids, documents all calculation nodes
(cells, groups, VBA).
Provider resolution (first match wins, no implicit default and no preferred vendor):
provider— custom LLMProvider instance or callablebase_url+model(orLINEXCEL_AI_BASE_URL+LINEXCEL_AI_MODEL) — any OpenAI-compatible endpoint, local or hosted
language selects the system prompt; see :data:linexcel.i18n.LANGUAGES.
max_workers caps the number of concurrent requests. Nodes that fail
are skipped with a :class:UserWarning; the cards that succeeded are
still returned.
max_tokens caps output per node (approximate; provider-dependent).
token_budget caps what the whole documentation run may cost, input
and output tokens together. It is counted against :attr:token_usage,
which spans the result's lifetime, so one ceiling covers this call and
every earlier one — the figure to set is the total you are willing to
pay for this workbook, not a per-node allowance. Nodes still queued when
the budget is reached are left undocumented with a :class:UserWarning
rather than silently billed; requests already in flight are allowed to
finish, so treat the ceiling as approximate.
>>> docs = result.document(base_url=..., token_budget=200_000)
... # doctest: +SKIP
Tokens consumed are added to :attr:token_usage.
Source code in src/linexcel/result.py
document_workbook ¶
document_workbook(*, api_key: str | None = None, model: str | None = None, base_url: str | None = None, provider: ProviderLike | None = None, language: str = 'en', max_tokens: int | None = None, token_budget: int | None = None, include_context: bool = True) -> str
Document the workbook structure and calculation flow via AI.
The response is grounded in workbook-level deterministic lineage data.
Pass it to :meth:to_html or :meth:save_html as workbook_doc to
display it in the viewer's separate overview tab.
include_context adds :attr:workbook_context to the dossier: the
sheet previews, cell comments, merged ranges, frozen panes and hidden
columns — the same cues the sheet screenshots show. Without it the model
sees how the workbook computes but not what it looks like, and describes
a graph rather than a file. Set it to False to keep cell contents
local; the lineage (formulas and their values) is sent either way.
Provider resolution is the same as :meth:document, and tokens
consumed are added to :attr:token_usage. max_tokens caps the
output length (approximate; provider-dependent), while token_budget
caps cumulative spend on this result and raises :class:AiDocError if
earlier calls already exhausted it.
Source code in src/linexcel/result.py
to_html ¶
to_html(*, title: str | None = None, full_document: bool = True, docs: dict[str, str] | None = None, workbook_doc: str | None = None, screenshots: Screenshots | None = None, language: str = 'en') -> str
Standalone HTML document (Cytoscape) — openable in a browser.
If docs is provided (from :meth:document), AI documentation
for each node is embedded in the detail panel. If workbook_doc is
provided (from :meth:document_workbook), it is shown in a separate
overview tab. If screenshots is provided (paths or base64), they
are displayed in a preview tab.
Source code in src/linexcel/result.py
analyze ¶
Analyze an Excel workbook and return a :class:LineageResult.
Parameters¶
source : str | Path | bytes | binary file
Path to the file, raw content, or file object opened in rb.
filename : str, optional
Logical name (used for labels and VBA detection).