preppy - a Preprocessor for Python

raw JSON →
5.1.0 verified Mon Apr 27 auth: no python

preppy is a Python preprocessor for generating text output from templates. It compiles template files into Python modules for fast execution. Current version 5.1.0, maintained by ReportLab, with irregular release cadence.

pip install preppy
error ModuleNotFoundError: No module named 'preppy'
cause preppy is not installed.
fix
Run 'pip install preppy'.
error AttributeError: module 'preppy' has no attribute 'getModule'
cause Wrong import (e.g., 'from preppy import preppy').
fix
Use 'import preppy' and call preppy.getModule().
error preppy.PreppyError: Could not find template file
cause Filename or path is incorrect, or extension missing.
fix
Ensure filename includes .prep extension or use source_extension parameter.
breaking Version 3.x dropped Python 2 support. Templates compiled with older versions may not be compatible.
fix Recompile templates with preppy 5.x.
breaking In version 5.x, the module caching behavior changed: getModule now caches compiled modules by default. Use noCaching parameter to disable.
fix Add noCaching=True if you need fresh compilation each time.
gotcha Template files must have a .prep extension by default, or specify source_extension in getModule.
fix Use preppy.getModule('file.prep') or preppy.getModule('file', source_extension='.prep').
gotcha getOutput does not accept keyword arguments for variables; pass a dictionary as first argument.
fix Use template.getOutput({'var': value}) instead of template.getOutput(var=value).

Compile and run a template file named 'template.prep' with a variable 'name'.

import preppy

template = preppy.getModule('template.prep', source_extension='.prep')
result = template.getOutput({'name': 'World'})
print(result)