Formualizer Docs
SheetPort

Sessions and Evaluation

How SheetPortSession manages state, evaluation options, and batch execution.

The SheetPortSession is the primary interface for interacting with a workbook through a SheetPort manifest. It manages the lifecycle of input writing, recalculation, and output reading.

Session Lifecycle

Creation

A session is created by binding a manifest to a workbook. The manifest can be built in code or loaded from YAML; see the quickstart. During creation, the session validates the manifest and checks that the workbook satisfies it (for example, that the sheets and cells it references exist).

State Management

A session is stateful: inputs you write stay in the workbook until you overwrite them. Reuse the same session for many evaluations; it is cheaper than creating a new one for every run.

Reading and Writing

Writing Inputs

Use write_inputs() to provide new data for input ports.

  • Validation: The whole update is validated against the manifest's schema and constraints (for example min, max, pattern) before anything is written. If any port fails, nothing is written.
  • Partial Updates: You can update a subset of inputs; values from previous writes persist until overwritten.

Reading Current State

  • read_inputs(): Inspect the current values of all input ports as they exist in the workbook.
  • read_outputs(): Read the current values of all output ports. This is often used after an evaluation, but can be called at any time.

Evaluation

evaluate_once(options)

This method triggers the calculation engine. It ensures all pending input writes are applied, recalculates the workbook formulas, and returns the resulting output port values.

EvalOptions

You can control the evaluation behavior using EvalOptions:

  • freeze_volatile: Treat volatile functions (like NOW() or RAND()) as constants based on their last known value.
  • rng_seed: Provide a seed for random number generation to ensure deterministic results across runs.
  • deterministic_mode: Enable strict determinism, which may disable certain non-deterministic engine features.

Batch Execution

For high-throughput scenarios, the BatchExecutor (available in some bindings) allows you to run multiple sets of inputs through the same session efficiently. This is ideal for Monte Carlo simulations, sensitivity analysis, or processing large datasets.

Error Handling

SheetPort uses structured error types to help you diagnose issues:

  • InvalidManifest: The manifest violates the FIO spec; each issue has a path such as ports[0].location. Python raises SheetPortManifestError; in JavaScript the error has an issues list.
  • MissingSheet, InvalidReference, UnsupportedSelector: The manifest does not fit the workbook, for example a sheet it names does not exist.
  • ConstraintViolation: An update passed to write_inputs() failed a schema constraint. Python raises SheetPortConstraintError; in JavaScript the error has a violations list naming each port.
  • LayoutExhausted, SelectorSafety: A header layout could not be resolved safely, for example no terminating blank row or marker was found within the scan limit.
  • InvariantViolation: An update names an unknown port or an output port, or a value or location does not fit its port (for example a scalar port whose defined name covers several cells).
  • Engine, Workbook: The calculation engine or the workbook reported an error.

On this page