Registry / web-framework / empy
library4.2.1pypypi✓ verified 86d ago

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 empy
INSTALL
IMPORT
SIG · EMPY
E
empy
web-frameworkpythonv4.2.1
Install
2.6s avg
Import
25ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.026s · 19.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.6s · import 0.023s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

expand
from em import expand
import empy
The primary API for string expansion is the 'expand' function found in the 'em' module (em.py). While 'empy' is the package name, 'em' is the module for core functionality. Attempting to directly 'import empy' as a module might not provide the expected API for templating, as 'empy' also refers to an internal 'pseudomodule' within the interpreter context.

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.

from em import expand template_string = '''Hello, @(name)!\nYour lucky number is @(2 * 3 * 7).\n@{for item in items:}\n - @item\n@{}\n''' context = { 'name': 'World', 'items': ['apple', 'banana', 'cherry'] } rendered_output = expand(template_string, globals_=context) print(rendered_output)
Debug
Known issues
breakingMajor breaking changes occurred in the 4.x series compared to 3.x. This includes relicensing from GPL to BSD, significant changes to markup syntax (e.g., `repr` markup changed to backquote, in-place markup syntax changed), and modifications to the embedding interface. The `Interpreter` constructor and the global `expand` function now strictly require keyword arguments.
fix
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_=...)`).
affects: 4.0.0 and later (from 3.x)
breakingInternal module names and constants were changed in 4.x. For example, the `OVERRIDE_OPT` constant, previously accessible, was removed or refactored, leading to `ImportError` for applications that relied on such internals (e.g., `colcon-core` issues).
fix
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.
affects: 4.0.0 and later
gotchaMulti-line Python statements within `@{...}` blocks must be flush with the left margin of the template. Python's significant indentation rules apply directly to these blocks, and incorrect indentation will lead to `IndentationError` or other parsing failures.
fix
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.
affects: All versions
gotchaThere are two distinct Python libraries with very similar names: `empy` (the templating system) and `EMpy` (Electromagnetic Python). They serve entirely different purposes and have different installation commands (`pip install empy` vs `pip install ElectromagneticPython`).
fix
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 ...`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'em'
This error frequently occurs in environments like ROS/Catkin when a conflicting Python package named 'em' (a different, older templating library) is installed and takes precedence over 'empy's 'em' module, or when 'empy' is not correctly installed or discoverable.
fix
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`).
cannot import name 'OVERRIDE_OPT' from 'em'
This specific import error arises when a system, such as `colcon`, depends on an older version of `empy` (typically 3.x) that exposed `OVERRIDE_OPT` within its `em` module, but `empy` version 4.x (or newer) is currently installed, which has removed or refactored this attribute as part of its modernization.
fix
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`.
SyntaxError: invalid syntax (or similar `SyntaxError` messages within empy template output)
EmPy templates embed Python code directly using markup like `@(...)` or `@%`. A `SyntaxError` occurs if the Python code within these constructs contains invalid Python syntax, such as incorrect indentation for multiline statements, unclosed parentheses, or misspelled keywords, which the Python interpreter cannot parse.
fix
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.
Upgrade
Version history
4.2.1latest on PyPI · released Feb 9, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources