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.5.0b4.tar.gz (20.8 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.5.0b4-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file mvin-0.5.0b4.tar.gz.

File metadata

  • Download URL: mvin-0.5.0b4.tar.gz
  • Upload date:
  • Size: 20.8 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.5.0b4.tar.gz
Algorithm Hash digest
SHA256 860a857a0c0ddfa6391d10012ec08072f3faf0899c8603541874f443e53627a6
MD5 68de70ee1ad6c344dcba82971f95951c
BLAKE2b-256 b6fbeeb60c88c8bfc1ca8bbbdf9fca14240ab55f3277b68e88c67d0f774d1295

See more details on using hashes here.

File details

Details for the file mvin-0.5.0b4-py3-none-any.whl.

File metadata

  • Download URL: mvin-0.5.0b4-py3-none-any.whl
  • Upload date:
  • Size: 17.3 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.5.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 fac74ad6b9654cc5d65b070a74ec9bfb156acd6c113dee9f5149592d63277f87
MD5 5ee5014f94689caae0388eef87076640
BLAKE2b-256 5ed1bb199e4a5aaf144c1b549d1e989e8ac1467c1474044c178390372de99596

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