Skip to content


Repository files navigation


A simple lazy Python Calculation Engine.


The module is still in development. You can install it by cloning this repository and using the poetry install command.

git clone
cd calcengine
python3 -mvenv --prompt calceng .venv
. ./.venv/bin/activate
poetry install

Alternatively, you can add to your existing poetry project:

poetry add git+

Or install via pip:

pip install git+

Core Dependencies

The core module for the calculation engine only uses core python standard library.

The demo spreadsheet application uses pyqt5, pandas, matplotlib and pillow.


First instantiate a CalcEngine and use watch decorator to register functions as nodes. Note that a function along with any arguments and keyword arguments make a unique node.

from calcengine import CalcEngine

ce = CalcEngine()
def a():
    print(" a")
    return 100
def b():
    print(" b")
    return a()
def c(x, y):
    print(f" c with x={x} and y={y}")
    return 2 * a() + x * y
def d(x, y=0):
    print(f" d with x={x} and y={y}")
    return 3 * b() + x - y
def e():
    print(" e")
    _x = d(5, y=-3)
    return c(2, 3) - 5 + _x
def f():
    print(" f")
    return d(0) + e()

Calling a function will cache all values and path during first run.

>>> f() f d with x=0 and y=0 b a e d with x=5 and y=-3 c with x=2 and y=3

And obviously a 2nd invocation will retrieve the final value from cache.

>>> f()

Invalidating a node by calling function helper method.

>>> e.invalidate()
>>> f() f e

Invalidating a node without arguments if previous call did have arguments won't have any effect.

>>> d.invalidate()
>>> f()

Whereas with arguments specified exactly as prior call will. Note the sensitivity of argument specification.

>>> d.invalidate(5, y=-3)
>>> f() f e d with x=5 and y=-3

It is also possible to add a trigger that will be called on completion of a function. This might be used to produce some form of data binding in applications.

def my_trigger(res):
    print(f"got {res}")

>>> c.node_calculated.append(my_trigger)
>>> c.invalidate(2, 3)
>>> f()
call f
call e
call c with x=2 and y=3
got 206

Demo application

Included is a simple spreadsheet demo. Read more here

Demo animation


To install the dependencies required by the demo. When cloning this repo also include the "demo" extras.

poetry install -E demo
python demo/spreadsheet/

To do

  • Support watching global variables.
  • Support multiprocessing.
  • Support asyncio?.

similar packages

Some similar packages spotted. None of them tested.


Simple Python Calculation Engine







No releases published


No packages published