Fast Excel-formula tooling (Python bindings)
Project description
Formualizer — Python Bindings
A blazing‑fast Excel formula tokenizer, parser, and evaluator powered by Rust, exposed through a clean, Pythonic API.
These bindings wrap the core formualizer‑core and formualizer‑eval crates and let you work with spreadsheet logic at native speed while writing idiomatic Python.
Key Features
| Capability | Description |
|---|---|
| Tokenization | Breaks a formula string into structured Token objects, preserving exact byte spans and operator metadata. |
| Parsing → AST | Produces a rich Abstract Syntax Tree (ASTNode) that normalises references, tracks source tokens, and fingerprints structure. |
| Reference Model | First‑class CellRef, RangeRef, TableRef, NamedRangeRef objects with helpers like .normalise() / .to_excel(). |
| Pretty‑printing | Canonical formatter — returns Excel‑style string with consistent casing, spacing, and minimal parentheses. |
| Visitor utilities | walk_ast, collect_references, collect_function_names, and more for ergonomic tree traversal. |
| Evaluation (opt‑in) | Bring in formualizer‑eval to execute the AST with a pluggable workbook/resolver interface. |
| Rich Errors | Typed TokenizerError / ParserError that annotate byte positions for precise diagnostics. |
Installation
Pre‑built wheels (recommended)
pip install formualizer
Build from source
You need a recent Rust toolchain (≥ 1.70) and maturin:
# one‑off – install maturin
pip install maturin
# from repo root
cd bindings/python
maturin develop # builds the native extension and installs an editable package
This compiles the Rust crates (formualizer‑*) into a CPython extension named formualizer.
Quick‑start
from formualizer import tokenize, parse
from formualizer.visitor import collect_references
formula = "=SUM(A1:B2) + 3%"
# 1️⃣ Tokenize
for tok in tokenize(formula):
print(tok)
# 2️⃣ Parse → AST
ast = parse(formula)
print(ast.pretty()) # indented tree
print(ast.to_formula()) # canonical Excel string
print(ast.fingerprint()) # 64‑bit structural hash
# 3️⃣ Analyse
refs = collect_references(ast)
print([r.to_excel() for r in refs]) # ['A1:B2']
Tip: You can build your own visitor by returning
VisitControl.SKIPorSTOPto short‑circuit traversal.
Public API Surface
Convenience helpers
tokenize(formula: str) -> Tokenizer
parse(formula: str, include_whitespace: bool = False) -> ASTNode
Core classes (excerpt)
Tokenizer— iterable collection ofToken;.render()reconstructs the original string.Token—.value,.token_type,.subtype,.start,.end,.is_operator().Parser— OO interface when you need to parse the sameTokenizertwice.ASTNode—.pretty(),.to_formula(),.children(),.walk_refs()…- Reference types —
CellRef,RangeRef,TableRef,NamedRangeRef,UnknownRef. - Errors —
TokenizerError,ParserError(carry.messageand.position).
Visitor helpers (formualizer.visitor)
walk_ast(node, fn)— DFS with early‑exit control.collect_nodes_by_type(node, "Function")→ list[ASTNode]collect_references(node)→ list[ReferenceLike]collect_function_names(node)→ list[str]
Workspace Layout
formualizer/
│
├─ crates/ # Pure‑Rust core, common types, evaluator, macros
│ ├─ formualizer-core (tokenizer + parser + pretty)
│ ├─ formualizer-eval (optional interpreter + built‑ins)
│ ├─ formualizer-common (shared literal / error / arg specs)
│ └─ formualizer-macros (proc‑macro helpers)
│
└─ bindings/python/ # This package (native module + Python helpers)
The Python wheel links directly against the crates — there is no runtime FFI overhead beyond the initial C→Rust boundary.
Development & Testing
# run Rust tests
cargo test --workspace
# TODO: add pytest once Python‑side tests exist
When hacking on the Rust side, you can rebuild the extension in place:
maturin develop --release # faster extension; omit --release for debug builds
Roadmap
- Full coverage of Excel 365 functions via
formualizer‑eval - SIMD‑accelerated bulk range operations
- ChatGPT‑powered formula explanations 🎯
Have an idea or found a bug? Open an issue or PR — contributions are welcome!
License
Dual‑licensed under MIT or Apache‑2.0 — choose whichever you prefer.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file formualizer-0.1.0.tar.gz.
File metadata
- Download URL: formualizer-0.1.0.tar.gz
- Upload date:
- Size: 54.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f890d9d10bc6bed140505cf4d8fc1a79c063e7e0c27b801629a1182ccc7a545
|
|
| MD5 |
2555506b3df2531a22c78b75d97d13ff
|
|
| BLAKE2b-256 |
254240524fad7ff5ffc2d6b18d0ddc80d40731f2a21fe11ae3c440220236c89d
|
File details
Details for the file formualizer-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: formualizer-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1cbcfe8e77927f2391567fd7d50e6d0ae55ea12adfd129bef0652962c32cac0
|
|
| MD5 |
d166237398eaee846b97620fbf224114
|
|
| BLAKE2b-256 |
f6a61dfe204c67f9d4e5b6851331c7d934e6cdda653c02eaa26ada8dff9cfc30
|