Q:

python module/framework for math formulas?

I am trying to create an open-ended report structure where folks can define reports with essentially string-replaced formulas.
Something like:
'my_report': {
    'my_stat': '{units}/({units}+{other_units})*100'
}

And then these will be parsed with a dict containing all the values allowable in the report. 
There are a hundred or so possible keys and the framework needs to allow any valid math formula so you'd have something like:
my_stat = formula.parse(d)

Where d is the dict of actual values.
Is there a framework or module that already supports this?

A:

You can develop it yourself using a combination of format and eval:
class Formula():
    def __init__(self, formula):
        self.formula = formula

    def parse(self, d):
        return eval(self.formula.format(**d))

formula = Formula('{units}/({units}+{other_units})*100')
d = {'units': 100.0, 'other_units': 50.0}

my_stat = formula.parse(d)

print my_stat

returns
66.6666666667

