Infix pre-parser for numexpr
This is an infix parser for the basic syntax outlined in the numexpr user guide.
It may not correctly parse every supported numexpr expression, but it does offer strict parsing of a subset of numexpr syntax.
It is defined using the pyparsing package
Not supported at this time/known issues
- String constants are not yet supported, and will not be sucessfully parsed
- the axis keyword in numexpr
sumandprodwill not be sucessfully parsed
It can be used as numexpr pre-parser/validator:
- ensure string expressions are strictly infix expressions
- get detailed error feedback for parsing errors via pyparsing
- assert only function names that are supported in numexpr
- assert identifiers are valid python identifiers
- assert that only the numexpr unary and binary operators are used
constant values supported are:
- floating point with scientific and complex notation
- integers
Installation
pip install numexpr_preparser
Example usage:
Using as a pre-parser, to reject expressions that are not strictly infix
notation with the documented numexpr syntax
import numexpr
from numexpr_preparser import parser as preparser
def numexpr_safe_evaluate(ex: str, *args, **kwargs):
parse_success, results = preparser.get_parser().run_tests(
ex, print_results=False
)
if not parse_success:
raise ValueError(results[0][1])
return numexpr.evaluate(ex, *args, **kwargs)
Metadata
Release files for numexpr-preparser 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| numexpr_preparser-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for numexpr_preparser-1.0.0-py3-none-any.whl |
Release files / numexpr_preparser-1.0.0-py3-none-any.whl
| Download URL | numexpr_preparser-1.0.0-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ada2f1c73ecfe2213078e813284e298e18447013e5820e141493c9339cd72bdf
|
|
BLAKE2b-256 checksum How to use checksums |
f79a2d4166919f8897711b5cc5b808dd6af2f7919cd4ce82e03ddb90abccb7d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for numexpr-preparser 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.