leval is a Python library that provides a safe and limited evaluator for untrusted Python expressions, aiming to prevent arbitrary code execution while allowing controlled calculations. It is currently at version 1.3.0 and actively maintained, with recent updates focusing on feature enhancements and internal improvements.
pip install levalVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `leval.simple.evaluate` for evaluating expressions with provided context, including basic arithmetic, string manipulation, and conditional logic. It also highlights the `loose_is_is_not` parameter for controlling identity operator behavior introduced in version 1.2.0.
If strict identity (`id()`) comparison is required, set `loose_is_is_not=False` when calling `evaluate()` or initializing `Leval`.
Update exception handling logic to specifically catch `leval.exceptions.InvalidAttributeError` if you need to differentiate it, or ensure you're catching `AttributeError` (which it subclasses).
Always audit the objects and functions exposed in the evaluation context (`**context`, `globals`, `locals`) to ensure they do not introduce security vulnerabilities or allow access beyond what is intended.
No dependency data recorded yet.