{"id":9588,"library":"closure-soy","title":"Google Closure Soy Templates for Python","description":"closure-soy provides a Python wrapper for Google Closure's Soy template compiler and renderer. It allows Python applications to compile .soy files to JavaScript and render Soy templates. The library is very old, with its last release being `20121221`, and is no longer maintained.","status":"abandoned","version":"20121221","language":"en","source_language":"en","source_url":"https://github.com/google/closure-soy","tags":["templating","closure","soy","frontend","legacy","python2"],"install":[{"cmd":"pip install closure-soy","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"symbol":"Renderer","correct":"from closure_soy import Renderer"},{"symbol":"CompileToJs","correct":"from closure_soy.compiler import CompileToJs"}],"quickstart":{"code":"import os\nfrom closure_soy import Renderer\nfrom closure_soy.compiler import CompileToJs\n\n# NOTE: This library is a Python 2.x era wrapper for the Java-based Closure Soy Compiler.\n# To run this code, you MUST have Java installed and available in your PATH,\n# and you MUST provide the path to the Closure Soy Compiler JAR file.\n# You will also need actual .soy template files.\n\n# Placeholder for the Soy compiler JAR path (e.g., soy-compiler.jar)\nSOY_JAR_PATH = os.environ.get('SOY_JAR_PATH', '/path/to/soy-compiler.jar')\n\n# Placeholder for your .soy template files (e.g., ['path/to/my_templates.soy'])\nTEMPLATE_FILES = [f for f in os.environ.get('SOY_TEMPLATE_FILES', '').split(',') if f]\nif not TEMPLATE_FILES:\n    TEMPLATE_FILES = ['/path/to/example.soy'] # Replace with a valid .soy file path\n\n# Example 1: Compiling Soy templates to JavaScript\ntry:\n    # output_dir = '/tmp/js_templates'\n    # os.makedirs(output_dir, exist_ok=True) # Python 3 syntax\n    # CompileToJs(SOY_JAR_PATH, TEMPLATE_FILES, output_dir)\n    # print(f\"Soy templates compiled to {output_dir}\")\n    print(\"To compile: Uncomment and set SOY_JAR_PATH, TEMPLATE_FILES, and output_dir.\")\n    print(\"Example: CompileToJs(SOY_JAR_PATH, TEMPLATE_FILES, '/tmp/js_templates')\")\nexcept Exception as e:\n    print(f\"Failed to compile templates (expected if setup is not complete): {e}\")\n\n# Example 2: Rendering a Soy template\ntry:\n    renderer = Renderer(SOY_JAR_PATH, TEMPLATE_FILES)\n    # Assuming 'my.template.name' is a template defined in one of TEMPLATE_FILES\n    # and 'data' is a dictionary matching the template's parameters.\n    # rendered_html = renderer.render('my.template.name', {'param': 'value'})\n    # print(f\"Rendered HTML: {rendered_html}\")\n    print(\"To render: Uncomment and set SOY_JAR_PATH, TEMPLATE_FILES. Provide a template name and data.\")\n    print(\"Example: renderer.render('my.template.name', {'param': 'value'})\")\nexcept Exception as e:\n    print(f\"Failed to render template (expected if setup is not complete): {e}\")\n","lang":"python","description":"This quickstart demonstrates the API for compiling and rendering Soy templates using `closure-soy`. Note that this library acts as a wrapper around the Java-based Soy compiler. You must have Java installed, provide the path to the Soy compiler JAR, and point to your `.soy` template files for this code to function correctly."},"warnings":[{"fix":"Use a Python 2.x environment or migrate to a modern templating solution for Python 3.","message":"This library was developed for Python 2.x and is incompatible with Python 3. Attempting to use it on Python 3 will result in `ImportError` or `SyntaxError`.","severity":"breaking","affected_versions":"All versions (20121221) when used with Python 3.x"},{"fix":"Ensure Java is installed and the Soy compiler JAR is accessible. Set `SOY_JAR_PATH` environment variable or pass the path directly when instantiating `Renderer` or `CompileToJs`.","message":"The `closure-soy` library is merely a Python wrapper for the Java-based Closure Soy Compiler. You must have a Java Runtime Environment (JRE) installed and available in your system's PATH, and you need to provide the file path to the Soy compiler JAR file for the library to function.","severity":"gotcha","affected_versions":"All versions (20121221)"},{"fix":"Consider modern alternatives for templating in Python, such as Jinja2, Mako, or dedicated JavaScript templating solutions if server-side rendering of Soy templates is not a strict requirement.","message":"The project is abandoned, with the last release in 2012 and no further maintenance. It's not suitable for new projects or modern Python environments.","severity":"deprecated","affected_versions":"All versions (20121221)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure `pip install closure-soy` was successful. Verify you are running Python 2.x (e.g., `python --version`). If on Python 3, this library will not work; consider alternatives.","cause":"The library is either not installed, or you are running a Python version (likely Python 3) with which it is incompatible.","error":"ImportError: No module named closure_soy"},{"fix":"This library is not compatible with Python 3.x. Use a Python 2.x interpreter or choose a modern Python 3 compatible templating engine.","cause":"The `closure-soy` codebase contains Python 2.x specific syntax which is invalid in Python 3.x, leading to a `SyntaxError` during import or execution.","error":"SyntaxError: invalid syntax (on Python 3.x)"},{"fix":"Install Java (JRE) on your system and ensure the `java` executable is available in your system's PATH. On Linux/macOS, check with `java -version`.","cause":"The Python wrapper tries to invoke the `java` command to run the Soy compiler, but the Java Runtime Environment (JRE) is either not installed or not in your system's PATH.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'java'"},{"fix":"Verify that the `soy_jar_path` variable or environment variable points to the correct, existing Soy compiler JAR file.","cause":"The path provided for `soy_jar_path` when initializing `Renderer` or `CompileToJs` is incorrect, or the file does not exist.","error":"OSError: Cannot find the Soy compiler JAR file at the specified path."}]}