Skip to main content

formulon

PyPI npm License Python Docs

Recalculate Excel workbooks and formulas from Python, with results checked against real Excel 365. No Excel install, no Windows, no COM automation: the wheel is pure Python around the engine compiled to WebAssembly, so one py3-none-any wheel runs anywhere wasmtime does.

Known differences from Excel are listed case by case in tests/divergence.yaml, each with a reason and the Excel build it was last verified on.

📖 Documentation  ·  Python guide  ·  API  ·  Batch recalculation

What's inside

  • Formula engine — 527 Excel function names, 512 implemented locally; dynamic arrays, LET / LAMBDA, and REGEX*. Coverage
  • Workbook I/O — read, recalculate and write .xlsx and .xlsb, including styles, conditional formatting, tables, pivot tables (refresh and grouping), charts, chartsheets, in-cell pictures, theme apply and save, and print layout; .xlsb carries pictures, charts and pivot tables too. A loaded workbook keeps its cached values where Excel would, and recalc_full() recomputes everything. A save of a workbook that holds something the target format cannot store fails with IoError (StatusCode.IO_FEATURE_NOT_WRITABLE) and writes nothing. File formats
  • Workbook editing — cells, sheets, rows and columns, styles, merges, comments, validations, pivot tables, print settings, furigana, Insert / Delete Cells and worksheet copy, through typed Workbook and Sheet APIs. API
  • Locale profiles — 28 Excel behavior profiles across fourteen locales on Mac and Windows hosts. Locale profiles
  • Excel oracle — formula results are compared bit for bit against goldens captured from Mac Excel 365 in fourteen locales. Oracle testing

Installation

pip install formulon   # Python 3.10+

wasmtime is the only runtime dependency; pip picks its platform build. Recalculation is serial in this package, with results identical to the threaded surfaces. Changes between releases are in the CHANGELOG; until 1.0 a minor release may break the API and a patch release does not.

Quick start

import formulon

print(formulon.evaluate_formula("=SUM(1,2,3)"))  # 6.0

v = formulon.evaluate_formula("=1/0")
print(type(v).__name__, v.code.name)  # ExcelError DIV0

Numbers come back as float, because every Excel number is a double: 6.0, not 6.

Excel errors come back as ExcelError values; a host-side failure raises FormulonError. Its subclasses are IndexOutOfRangeError, NotFoundError, AlreadyExistsError, InvalidArgumentError, FormulaSyntaxError, WorkbookClosedError, InvalidFileError and one class per status range (IoError, EvaluationError and the others). See Errors.

Recalculate a workbook

from formulon import Workbook

# Create input.xlsx first; any existing workbook file works the same way.
with Workbook.create_default() as seed:
    seed.save("input.xlsx")

with Workbook.load("input.xlsx") as wb:
    ws = wb.sheet(0)  # or wb["Sheet1"]
    ws["A1"] = 42
    ws.set_formula("A2", "=A1*2")
    print(wb.has_dirty_cells())  # True
    wb.recalc()
    print(wb.has_dirty_cells())  # False
    print(ws["A2"])  # 84.0

    wb.save("output.xlsx")

    print(ws.name, ws.index)  # Sheet1 0
    ws.set_values("A1", [[1, "x"], [True, None]])
    print(ws["A1"])  # 1.0

Every method that takes a cell accepts either (row, col) or an A1 string, and a rectangle argument accepts "A1:B2". ws["A1"] and ws[row, col] read and write native values; get_values and set_values move a block of cells. A string that starts with = is entered as a formula; enter untrusted text with ws.set_text("A1", text), which always stores text. In the default automatic calculation mode a read calculates pending cells first; in manual mode it returns the value as of the last recalc(), and wb.has_dirty_cells() tells whether edits are still waiting for one. ErrorCode.DIV0.display_name is "#DIV/0!".

A Sheet handle stays on the same sheet when sheets are added, moved or removed around it. wb.sheet(key) and wb[key] take an index or a name and raise NotFoundError or IndexOutOfRangeError when nothing matches (wb[-1] is the last sheet, while a negative index passed to wb.sheet() is IndexOutOfRangeError); wb.list_sheets() lists every sheet.

wb.close() or leaving the with block releases the workbook at that moment; wb.closed reports it, and any later call raises WorkbookClosedError. A workbook dropped without closing is released when the garbage collector reclaims it, which is best effort, so close workbooks you are done with. Workbook.load also takes bytes or a binary stream, and wb.save() without a destination returns the bytes.

Format cells

import formulon

with formulon.Workbook.create_default() as wb:
    ws = wb.sheet(0)
    ws.update_cell_format(
        "A1:B2",
        number_format="0.00%",
        font={"bold": True, "color": "#C00000"},
        fill={"foreground": "#FFF2CC"},
        alignment={"horizontal": formulon.HorizontalAlign.CENTER},
    )
    ws.update_cell_format("D:D", border={"left": {"style": formulon.BorderStyle.THIN}})

    fmt = ws.get_cell_format("A1")
    print(fmt.number_format, fmt.font.bold, fmt.fill.pattern.name)  # 0.00% True SOLID

update_cell_format merges only the groups and keys it is given into each cell's format; a column ("D:D"), row ("3:3") or whole-sheet range formats that axis, so cells entered there later take the format too. Equal formats share one style record.

Threads and memory

  • One WebAssembly instance serves the whole process, and calls into it are serialised, so threads do not run workbook code in parallel.
  • Memory the instance grew is not given back while the process lives.
  • The instance has a 32-bit address space.
  • A trap makes every open workbook unusable; start a new process.
  • For parallel work, use multiprocessing and give each process its own workbooks.

New workbooks use win-365-en_US; wb.set_profile_id(id) takes any of {mac,win}-365-{ja_JP,en_US,de_DE,fr_FR,zh_CN,ko_KR,th_TH,es_ES,es_MX,pt_BR,ru_RU,zh_TW,it_IT,nl_NL}. Switching profiles is covered in the root README.

Non-goals

VBA execution, legacy .xls, chart rendering, Power Query / DAX, live external connections, and a spreadsheet UI are permanently out of scope. See Non-goals.

License

Apache License 2.0. See also NOTICE.

Metadata

Release files for formulon 0.19.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for formulon 0.19.0
File Interpreter ABI Platform Actions
formulon-0.19.0-py3-none-any.whl Python 3 none any Details for formulon-0.19.0-py3-none-any.whl

Release files / formulon-0.19.0-py3-none-any.whl

Download URL formulon-0.19.0-py3-none-any.whl
Size 2.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
7e5236c78445a735fffa8402dbef06ded201f9bab35fe86522a47382d6f0ee55
BLAKE2b-256 checksum
How to use checksums
ba3571214a12e390a8533f6fac6809d4fdbfa8e8548b00b2b1bf3fd0033af0f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for formulon 0.19.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for formulon-0.19.0-py3-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page