Skip to main content

This package evaluates mathematics expressions written in string safely.

Project description

Math Parser

Math-Parser is a Python package to evaluate math expressions in strings using a LL-Compiler Algorithm with no dependencies, except the standard packages.

It's not recommended to use eval to evaluate strings in Python for security reasons. This packages has the intention to solve this problem with safety.

Install

Install the latest version directly from the source using Git:

git clone
cd Math-Parser
python setup.py install

Usage

To use this package, import the evaluate function and call it.

from math_parser import evaluate

expr = '2 * (10/2) + 5'
evaluate(expr)

>>> 15.0

The evaluate function can receive variables to use it on the expression.

expr = 'a0 + a1/10'
evaluate(expr, a0=2, a1=10)

>>> 3.0

In this version of the package it only accepts some operators:

  • Addition (+);
  • Subtraction (-);
  • Multiplication (*);
  • Division (/)
  • Exponentiation (^)

For now, it doesn't work with negative exponentiation.

Contact

If you want to contact me, email me: victor.soeiro.araujo@gmail.com

Acknowledgements

This code was based on Georg Nebehay algorithm. Please check his code and documentation for better understanding of this package, and give him a star.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Math-Parser-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Math_Parser-0.1.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file Math-Parser-0.1.2.tar.gz.

File metadata

  • Download URL: Math-Parser-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for Math-Parser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 51323b3d86156a8fd5253e6dc9fb8c22b7072f3f58587e4d94d576310c4342e6
MD5 f19cf4570fdb00faf997b71c6f1af7f6
BLAKE2b-256 b5d599d8cbd42931f8a256bb3779f91438dd865f7a911c77ae58b5f8fdd6c21b

See more details on using hashes here.

File details

Details for the file Math_Parser-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: Math_Parser-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for Math_Parser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14c207524dfdc2663c6d1e1e23c7c2163e797374b22d2affb712433e79adcc7b
MD5 c8875e687b1a485ab4f8947625728937
BLAKE2b-256 4b7a946ccc450f45d632e89fd5b30f174554b3afc3a0ea439f4b6e99cd41f9fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page