API documentation

python wrapper for tinyexpr

tinex.eval(expression, **variables) → float

Evaluate an expression

Parameters:
  • expression (Expression or str) – The expression. If a string, it must be ascii-encodable.
  • **variables (numbers.Real) – values assigned to variables
Returns:

result – The result of evaluation.

Return type:

float

Raises:

Examples

>>> import tinex as te
>>> te.eval('sqrt(a^2+b^2)', a=3, b=4)
5.0
>>> te.eval('cos(pi)')
-1.0
>>> te.eval('-5/0')
-inf
class tinex.Expression

a compiled expression

Parameters:
  • body (str) – the text body of the expression
  • varnames (str) – variable names as a space-seperated string.

Example

>>> Expression('(sin(42) * alpha) / (beta + 45^3)',
...            varnames='beta alpha')
<Expression: (sin(42) * alpha) / (beta + 45^3)>

Todo

  • make evaluation threadsafe
  • implement evaluate with positional args