Installation

mathparse can be installed using pip:

pip install mathparse

Usage

from mathparse import mathparse

mathparse.parse('50 * (85 / 100)')
>>> 42.5

mathparse.parse('one hundred times fifty four', language='ENG')
>>> 5400

mathparse.parse('(seven * nine) + 8 - (45 plus two)', language='ENG')
>>> 24

Note

The language parameter must be set in order to evaluate an equation that uses word operators. The language code should be a valid ISO 639-2 language code.

Development

To generate the documentation locally, clone the repository and install the development requirements:

git clone https://github.com/gunthercox/mathparse.git
cd mathparse
pip install .[test]

Then, from the root of the repository, run:

sphinx-build -nW -b dirhtml docs/ html/

You can then open the generated HTML files in the html/ directory, or serve them using a command such as:

python -m http.server --directory html 8000

To run the test suite, use unittest:

python -m unittest discover tests

To release a new version, update the version number in mathparse/__init__.py, then run:

python -m build

The Python package files are uploaded to PyPi using:

twine upload dist/*