vinci1it2000 / formulas

Excel formulas interpreter in Python.
https://formulas.readthedocs.io/
European Union Public License 1.1
342 stars 75 forks source link

Accumulator / Stateful / async functions #115

Open dberardo opened 1 year ago

dberardo commented 1 year ago

I am evaluating the usage of this library to perform simple simulations based on different type of functions.

Before I start contributing to the code myself, i have a couple of questions:

And also: Can input arguments be given in a more flexible way? Can we use dictionaries/kwargs, where order of arguments doesn't metter, and. Can we also pass null values to excel-like functions?

dberardo-com commented 1 year ago

also: would you endorse usage of caching libraries to speed up the computation of custom formulas ? or would it inerhently clash with the nature of the schedula library ?

example:

from cachetools import cached

shared_cache = dict()

@cached(
    cache=shared_cache,
    key=lambda a, b, c=None: "a" if c is None else "b"
)
def foo(a, b, c=None):
    print("foo")

import formulas
FUNCTIONS = formulas.get_functions()
FUNCTIONS['MYFUNC'] = foo
func = formulas.Parser().ast('=MYFUNC(1, 2)')[1].compile()