Formulas

1.3.4 · active · verified Wed Apr 15

Formulas is a Python library that implements an interpreter for Excel formulas, parsing and compiling Excel formula expressions. It can also compile Excel workbooks to Python code and execute them without needing a Microsoft Excel COM server. The current version is 1.3.4, released on March 11, 2026, with an active, though irregular, release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse and compile a basic Excel formula using the `Parser` class and how to extend the interpreter with custom Python functions. It showcases two core capabilities of the library: formula evaluation and customization.

import formulas

# 1. Parse and compile a simple Excel formula
parser = formulas.Parser()
ast_node = parser.ast("=SUM(10, 20)")[1] # [1] gets the formula node
compiled_func = ast_node.compile()
result_sum = compiled_func() # Expected: 30
print(f"Result of '=SUM(10, 20)': {result_sum}")

# 2. Add a custom function
FUNCTIONS = formulas.get_functions()
FUNCTIONS['MYCUSTOMADD'] = lambda x, y: x + y + 100

custom_func_node = parser.ast("=MYCUSTOMADD(5, 7)")[1]
compiled_custom_func = custom_func_node.compile()
result_custom = compiled_custom_func() # Expected: 5 + 7 + 100 = 112
print(f"Result of '=MYCUSTOMADD(5, 7)': {result_custom}")

view raw JSON →