SheetPort Quickstart
Turn a loan calculator into a typed function in Python, JavaScript and Rust, with the manifest built in code or loaded from YAML.
This quickstart turns a small loan calculator into a typed function. The workbook computes a monthly payment in Calculator!B4 from a principal, an annual rate and a term in B1:B3. The manifest declares those four cells as ports; the session writes the inputs, recalculates and returns the payment.
1. Build the manifest in code
Each language has helpers that fill in the parts of the manifest that rarely change: the spec version, each port's shape, and { a1: ... } around a plain cell address. The result is the same structure a YAML manifest describes, so the two forms are interchangeable.
import formualizer as fz
from formualizer.sheetport import Input, Manifest, Output
# The model: B4 computes the monthly payment from B1:B3.
wb = fz.Workbook() # or fz.load_workbook("loan.xlsx")
wb.add_sheet("Calculator")
wb.set_formula("Calculator", 4, 2, "=PMT(B2/12, B3, -B1)")
manifest = Manifest(
"loan-calculator",
name="Loan calculator",
ports=[
Input("principal", "Calculator!B1", type="number", constraints={"min": 0}),
Input("rate", "Calculator!B2", type="number"),
Input("term_months", "Calculator!B3", type="integer"),
Output("monthly_payment", "Calculator!B4", type="number"),
],
)
session = fz.SheetPortSession(wb, manifest)
session.write_inputs({"principal": 250_000, "rate": 0.045, "term_months": 360})
outputs = session.evaluate_once(freeze_volatile=True)
print(outputs["monthly_payment"]) # 1266.71...Input and Output take the port id and a location; type= declares a single cell. A plain dict with the canonical structure works anywhere a Manifest does.
2. Or load it from YAML
The same manifest as a file, loan-calculator.fio.yaml:
spec: fio
spec_version: "0.3.0"
manifest:
id: loan-calculator
name: Loan calculator
ports:
- id: principal
dir: in
shape: scalar
location: { a1: "Calculator!B1" }
schema: { type: number }
constraints: { min: 0 }
- id: rate
dir: in
shape: scalar
location: { a1: "Calculator!B2" }
schema: { type: number }
- id: term_months
dir: in
shape: scalar
location: { a1: "Calculator!B3" }
schema: { type: integer }
- id: monthly_payment
dir: out
shape: scalar
location: { a1: "Calculator!B4" }
schema: { type: number }Load it in place of the code-built manifest:
session = fz.SheetPortSession.from_manifest_yaml(yaml_text, wb)SheetPortSession.from_manifest_path(manifest_path, workbook_path) opens both files. Manifest.to_yaml() writes a code-built manifest out as YAML.
3. Constraints
The principal port has constraints: { min: 0 }. An update that breaks a constraint is rejected as a whole, so write_inputs({"rate": 0.05, "principal": -1}) writes neither value. Python raises SheetPortConstraintError, JavaScript throws an error whose violations name each failing port, and Rust returns SheetPortError::ConstraintViolation.
The manifest format lists every constraint, shape and location, including ranges, records and tables located by defined name or by the rows under a header.