Python Mathematical Expression Evaluator
pip install py-expression-evalPython Mathematical Expression Evaluator
Based on js-expression-eval, by Matthew Crumley (email@matthewcrumley.com, http://silentmatt.com/) https://github.com/silentmatt/js-expression-eval
Ported to Python and modified by @cansadadeserfeliz.
You are free to use and modify this code in anyway you find useful. Please leave this comment in the code to acknowledge its original source. If you feel like it, I enjoy hearing about projects that use my code, but don't feel like you have to let me know or ask permission.
Installation
pip install py_expression_eval
Tests
python setup.py test
Documentation
All the classes and methods of py-expression-eval were written as similar as possible to their analogues from js-expression-eval to make it easier to use for validation on back-end side.
Parser
Parser is the main class of the library that contains the methods to parse, evaluate and simplify mathematical expressions. In order to use the library you need to create an instance of this class:
> from py_expression_eval import Parser
> parser = Parser()
Once you instantiated Parser class, you can create Expression object using parse method:
> parser.parse('2 * 3')
Out: <py_expression_eval.Expression instance at 0x7f40cc4e5ef0>