EmPy is a powerful, robust, and mature templating system for Python that allows embedding Python code directly into template text. It processes source documents containing special markup (default: '@') to produce output. The library is currently at version 4.2.1 and has an active development status, with recent updates modernizing its features and Python compatibility.
pip install empyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use EmPy's `expand` function to process a template string with embedded Python expressions and statements. The template uses '@(expression)' for inline evaluation and '@{...}' for Python code blocks. A dictionary is passed as the `globals_` argument to provide the context for template variables.
Review the official 4.x documentation and the `ANNOUNCE.html#changes` for specific migration details. Update markup syntax, and ensure all API calls to `em.Interpreter` and `em.expand` use keyword arguments (e.g., `expand(template, globals_=...)`).
Avoid relying on EmPy's internal constants or module structure. If specific functionalities are needed, refer to the official API for supported methods. Downgrade to 3.x if critical functionality depends on removed internals and a migration is not immediately feasible.
Ensure that all lines within `@{...}` statement blocks are aligned to the leftmost column of the template content, unless they are intentionally indented as part of a Python code block (e.g., inside a function definition). Consistent indentation is key.Verify that you are installing and using the correct library based on your intended application. For templating, ensure `empy` is installed and imported as `from em import ...`.
First, uninstall the potentially conflicting `em` package (`pip uninstall em`). Then, ensure `empy` is installed or reinstalled (`pip install empy`). If a specific older version of `empy` is required by your build system (e.g., for compatibility with `colcon` or `PX4`), install that specific version (e.g., `pip install empy==3.3.4`).
Downgrade the `empy` package to a compatible older version, such as `3.3.4`, which still provides the `OVERRIDE_OPT` attribute. For example: `pip uninstall empy && pip install empy==3.3.4`.
Carefully review the Python code embedded within your EmPy template for common Python syntax errors. Pay particular attention to proper indentation for multi-line statements (which are significant in Python), correct use of EmPy's markup (e.g., `\` for line continuation or enclosing expressions in parentheses for multiline expressions), and ensuring all Python constructs are valid.
No dependency data recorded yet.