Safer Sympify
Convert unsanitized user input into SymPy expression.
This does not prevent all possible attacks. However, this is much safer than using eval(), which SymPy still does.
See SymPy PR12524 for more details: https://github.com/sympy/sympy/pull/12524
Examples
Create a SymPy expression from user input.
This uses pure Python syntax.
Whitelisted operators and functions only are allowed.
>>> expr = SaferSympify().str2sympy('-sqrt(1 + a**b*b)/((a**b)*b+1)')
>>> expr
-1/sqrt(a**b*b + 1)
Get free symbols:
>>> sorted(expr.free_symbols, key=lambda x: str(x))
[a, b]
Evaluate expression:
>>> expr.evalf(subs={'a': 1, 'b': 3, 'c': 5}) # Note extra values can be passed too
-0.500000000000000
Simplify expression:
>>> expr.simplify()
-1/sqrt(a**b*b + 1)
Pretty-print expression as Latex (could be displayed in browser with MathJax)
>>> sympy.latex(expr)
'- \\frac{1}{\\sqrt{a^{b} b + 1}}'
Metadata
Release files for safersympify 0.1.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| safersympify-0.1.18.tar.gz | 2.6 kB | Without provenance | Details for safersympify-0.1.18.tar.gz |
Release files / safersympify-0.1.18.tar.gz
| Download URL | safersympify-0.1.18.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f22d5b2dae200a28e29917da71cf5851d6bc03cc1c3c322c3326c8c19a546b5b
|
|
BLAKE2b-256 checksum How to use checksums |
6f76de0769208375bc242c72c60b4f1b5601a83a853c2627a19498c6cbdcd9e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Security for safersympify 0.1.18
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.