Skip to main content

Package for Python that evaluates math expressions from strings

Project description

Mathematical Expressions for Python

tests status

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


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.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

mathex-0.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file mathex-0.1.0.tar.gz.

File metadata

  • Download URL: mathex-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for mathex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b62d5c1836b32e26524e0c2860199d6c76125537d37ac92ea921879625473428
MD5 4e875950e8736ce62bf3f29dc9a07bc7
BLAKE2b-256 20fca70a55adfb128d8a8a77b2d5c6eb1c011b9e8813206a9fe1cb09571eb436

See more details on using hashes here.

File details

Details for the file mathex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mathex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for mathex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 828c8aa5164fe54717b56d408b070d859ff08f978c03e143f6bbf2ba5d8cffbb
MD5 fee552716d8f60362ba31becc0352873
BLAKE2b-256 9ad9c30941c7aec4fa23e3626a1674ee6daace468122abc7f990a8b8cc72b872

See more details on using hashes here.

Supported by

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