Skip to main content

Minimum Viable Interpreter (for single Excel formulas)

Project description

📄 mvin: Minimum Viable Interpreter for Excel Formulas

PyPI Version License Buy Me a Coffee

mvin is a lightweight, dependency-free interpreter for evaluating single Excel formulas. Built on a modified Dijkstra’s shunting yard algorithm, it supports extendable operator and function libraries, allowing customization without modifying the core codebase.

Mvin is designed to be simple, efficient, and easily extendable Excel's formulas interpreter under a permissive MIT or Apache 2.0 license. Buy Me A Coffee


✨ Features

  • 🚀 Lightweight & No Dependencies – Works out-of-the-box.
  • 🔌 Extendable Functions & Operators – Easily add new logic.
  • 🧵 Thread-Safe Design – Safe for concurrent execution (needs validation).
  • 📜 Tokenizer-Agnostic – Works with openpyxl and other tokenizers.
  • 📂 Simple Licensing – MIT or Apache 2.0.

📦 Installation

You can install mvin via PyPI:

pip install mvin

🚀 Usage

Basic Formula Evaluation

To use mvin, you need a tokenizer that returns tokens with the following properties:

  • type (string)
  • subtype (string)
  • value (any)

A predefined set of tokens is available in the module, but you can also use openpyxl for tokenization.

from mvin import TokenNumber, TokenOperator
from mvin.interpreter import get_interpreter

tokens = [TokenNumber(1), TokenOperator("+"), TokenNumber(2)]
callable_f = get_interpreter(tokens)
if callable_f is not None:
    result = callable_f({}) # Calling with empty reference/value dictionary
    # result = 3

💡 Use Cases & Examples

mvin is designed for lightweight, extendable Excel formula evaluation, making it ideal for various scenarios. Here are some common use cases:

1. Conditional Formatting Evaluations --> Automate rules outside of Excel.

Since mvin was originally built as the core interpreter for condif2css (to be released), it excels at evaluating conditions used in Excel’s conditional formatting.

2. Simple Data Validation Rules --> Validate form inputs, API data, or CSV file contents.

mvin can be used to apply spreadsheet-style validation to incoming data.

3. Lightweight Formula Evaluation in Applications --> Implement simple Excel formula support in a web app or database.

If you need Excel-like formula evaluation but don’t want to depend on a full workbook engine like formulas or xlcalculator, mvin offers a minimalist alternative.


📖 Supported Operators & Functions

Operators

The mvin interpreter supports a comprehensive set of numeric and comparison operators:

Arithmetic Operators

Operator Description
+ Addition
- Substraction
*Multiplication
/Division
^Exponentiation

Logical Operators

Operator Description
=Equal to
!=Not equal to
<>Not equal to (alternative notation)
>Greater than
>=Greater than or equal to
<Less than
<=Less than or equal to

📌 Built-in Functions

Unlike full-fledged Excel formula interpreters, mvin includes only a minimal set of built-in functions, as it was originally designed for conditional formatting evaluation:

Function Description
NOT(value) Returns the logical negation of a boolean value.
ISERROR(value) Returns TRUE if the given value represents an error.
SEARCH(substring, text, [start]) Finds the position of substring within text, optionally starting from start index.

For more advanced use cases, users can extend the function library by passing a custom dictionary of functions to the interpreter.


⚠️ Limitations & Roadmap

Current Limitations

  • Limited Built-in Functions – Only NOT, ISERROR, and SEARCH are available. Users must define additional functions as needed.
  • No Direct Workbook Integration – Unlike formulas, mvin does not evaluate references across sheets or workbooks.
  • No Built-in Tokenizer – Requires an external tokenizer (e.g., openpyxl) to process formulas.

Planned Enhancements

  • Improved Function Library – More Excel-like functions such as IF, AND, and OR may be added in future versions.
  • Thread-Safety Validation – While designed for thread safety, formal testing is needed.

🛠️ Testing & Code Coverage

mvin includes a comprehensive test suite with 93% test coverage.

To run the tests, use:

pytest tests/

If you contribute to mvin, please ensure your changes do not reduce coverage.


⚖️ Comparison with Other Excel Interpreters

Featuremvinformulasxlcalculator
LicenseMIT / Apache 2.0GPL-3.0MIT
DependenciesNonePandas, NumPyNumPy, OpenPyXL
Function SupportMinimal (NOT, ISERROR, SEARCH)ExtensiveExtensive
OperatorsArithmetic & ComparisonsArithmetic & LogicalArithmetic & Logical
Thread SafePotentially (Not Tested)
Tokenizer Required?Yes (e.g., OpenPyXL)NoNo
Designed forConditional FormattingFull WorkbookFull Workbook

mvin is ideal for lightweight, extendable formula evaluation, particularly in scenarios like conditional formatting where a full Excel engine is unnecessary.


📜 Changelog & Versioning

Version 0.5.0b2 (Initial Release)

🚀 First public release of mvin with the following features:

  • Supports numeric and comparison operators: +, -, *, /, ^, =, !=, <>, >, >=, <, <=.
  • Minimal built-in function set: NOT, ISERROR, SEARCH.
  • Extendable architecture: Custom operators and functions.
  • Tokenizer-agnostic design: Requires an external tokenizer.
  • No dependencies: Pure Python implementation.
  • Designed for conditional formatting: Built for condif2css.

Future releases will focus on:

  • Adding more built-in functions (IF, AND, OR, etc.).
  • Thread-safety validation.

License

mvin is licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in mvin by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mvin-0.11.0b1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mvin-0.11.0b1-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file mvin-0.11.0b1.tar.gz.

File metadata

  • Download URL: mvin-0.11.0b1.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.13.1 Darwin/24.3.0

File hashes

Hashes for mvin-0.11.0b1.tar.gz
Algorithm Hash digest
SHA256 0aca7de8f325f76391ba5ca201fd1c2ff9737719969268a1dca3fd233eb82f66
MD5 3897da72094d280940de56bf0016207c
BLAKE2b-256 ae068b022a0c88725ce4eed34bc3d8bfff7ebdc5560d98f4907db7377edb9563

See more details on using hashes here.

File details

Details for the file mvin-0.11.0b1-py3-none-any.whl.

File metadata

  • Download URL: mvin-0.11.0b1-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.13.1 Darwin/24.3.0

File hashes

Hashes for mvin-0.11.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f7202286aaf3eeae3d6580a953dbcc3fa785c2097cc63cf661b910c4cf7dcb4
MD5 8db16ff2ca7f237021a28df1a51ee2d2
BLAKE2b-256 af42f733a91805647d2791fe181d12db2fdc3654be3ce81bdfcffdede8fccd79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page