{"id":6357,"library":"empy","title":"EmPy Templating System","description":"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.","status":"active","version":"4.2.1","language":"python","source_language":"en","source_url":"http://www.alcyone.com/software/empy/","tags":["templating","code generation","text processing","pythonic","embeddable"],"install":[{"cmd":"pip install empy","lang":"bash","label":"Install EmPy"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import empy","symbol":"expand","correct":"from em import expand"}],"quickstart":{"code":"from em import expand\n\ntemplate_string = '''Hello, @(name)!\\nYour lucky number is @(2 * 3 * 7).\\n@{for item in items:}\\n  - @item\\n@{}\\n'''\n\ncontext = {\n    'name': 'World',\n    'items': ['apple', 'banana', 'cherry']\n}\n\nrendered_output = expand(template_string, globals_=context)\nprint(rendered_output)","lang":"python","description":"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."},"warnings":[{"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_=...)`).","message":"Major 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.","severity":"breaking","affected_versions":"4.0.0 and later (from 3.x)"},{"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.","message":"Internal 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).","severity":"breaking","affected_versions":"4.0.0 and later"},{"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.","message":"Multi-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.","severity":"gotcha","affected_versions":"All versions"},{"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 ...`.","message":"There 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`).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'4.2.1':41 'activ':45 'allow':16 'code':19,58 'compat':56 'contain':28 'current':38 'default':31 'develop':46 'direct':20 'document':27 'embed':17 'embedd':63 'empi':1,4 'featur':53 'generat':59 'librari':36 'markup':30 'matur':10 'modern':51 'output':34 'power':7 'process':25,61 'produc':33 'python':14,18,55,62 'recent':49 'robust':8 'sourc':26 'special':29 'status':47 'system':3,12 'templat':2,11,22,57 'text':23,60 'updat':50 'version':40","created_at":"2026-04-15T05:33:47.263384+00:00","updated_at":"2026-04-16T14:48:58.558195+00:00","problems":[{"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`).","cause":"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.","error":"ModuleNotFoundError: No module named 'em'"},{"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`.","cause":"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.","error":"cannot import name 'OVERRIDE_OPT' from 'em'"},{"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.","cause":"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.","error":"SyntaxError: invalid syntax (or similar `SyntaxError` messages within empy template output)"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.2.1","cli_name":"","cli_version":null,"type":"library","homepage":"http://www.alcyone.com/software/empy/","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/empy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}