Package for Python that evaluates math expressions from strings
Project description
Mathematical Expressions for Python
What is Mathex?
Mathematical Expressions (or Mathex for short) is a package for Python that evaluates mathematical expressions from strings at runtime according to Mathex Specification. It aims to provide fast, easy, customizable and, most importantly, safe evaluation with no dependencies.
The package is compatible with Python 3.7+.
How to use?
Using Mathex is super easy - just import, initialize and evaluate. That's it.
from mathex import Mathex, default_flags
# Use `Config` class and `DefaultFlags` to get default settings.
# For what settings are available, check out documentation.
config = Mathex(default_flags)
# Config class contains your settings along with custom
# variables and functions you inserted.
x = 1.5
config.add_constant("x", x)
# These variables and functions are then available for users
# to use in expressions.
input = "2x + 5"
# Mathex returns error and result of evaluation as a tuple.
result, error = config.evaluate(input)
# If error is None, evaluation completed without errors
if not error:
print(f"{input} is {result}") # Outputs `2x + 5 is 8`
Don't forget to install Mathex using pip:
python -m pip install mathex
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mathex-0.2.0.tar.gz
(8.3 kB
view details)
Built Distribution
mathex-0.2.0-py3-none-any.whl
(10.8 kB
view details)
File details
Details for the file mathex-0.2.0.tar.gz
.
File metadata
- Download URL: mathex-0.2.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 875633790cbdab72b0266644aae2d4cf884bb1a0ef606098ab582a4fe8f52b0f |
|
MD5 | 044198c435b6356121bb168b4f4e1013 |
|
BLAKE2b-256 | 5d723a95b893e06bc07fbb15541e71abffe1646cf6b78c95bbd78e55c36a1831 |
File details
Details for the file mathex-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: mathex-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6d7e977a966f10aa84f33ef1854a980c27f2fa237f22007a4d91f59ede31ce9 |
|
MD5 | 5e87188d4b500aedf379fd93898438d8 |
|
BLAKE2b-256 | 3d91da52d6c0dad2228375acd743946e4c8a29a3b5829c3652233402127c9726 |