pyfold

A constant-folding library for Python


Keywords
python ast parser scanner lexer compiler evaluator reflection
License
MIT
Install
pip install pyfold==1.0.1a1

Documentation

PyFold

PyFold is a set of tools and utilities for working with Python code.

Features

Eventually, the following features will be implemented:

  • An evaluator that is able to run Python programs in an isolated sandbox.
  • A constant folder that is able to pre-evaluate simple expressions while leaving the more complex ones untouched.
  • AST definitions that provide a more stable alternative to Python's built-in ast module
  • A Python parser written in pure Python that is fully compliant with the latest specifications.
  • A source code generator that generates readable Python code
  • Various tools and utilities for transforming PyFold's AST to and from Python's internal AST

Example Usage

from pyfold import Evaluator

my_eval = Evaluator()

my_eval.eval_expr("1 + 2") # returns 3

License

This software was written by Sam Veraveck and is licensed under the Apache 2.0 license.