Install & Compatibility
Where this runs
tested against v20121221 · 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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 29.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.6s · import 0.000s · 30MB
27MB installed
● package 27MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Renderer
✓ from closure_soy import Renderer
✗ from closure_soy import Renderer
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.
import os
from closure_soy import Renderer
from closure_soy.compiler import CompileToJs
# NOTE: This library is a Python 2.x era wrapper for the Java-based Closure Soy Compiler.
# To run this code, you MUST have Java installed and available in your PATH,
# and you MUST provide the path to the Closure Soy Compiler JAR file.
# You will also need actual .soy template files.
# Placeholder for the Soy compiler JAR path (e.g., soy-compiler.jar)
SOY_JAR_PATH = os.environ.get('SOY_JAR_PATH', '/path/to/soy-compiler.jar')
# Placeholder for your .soy template files (e.g., ['path/to/my_templates.soy'])
TEMPLATE_FILES = [f for f in os.environ.get('SOY_TEMPLATE_FILES', '').split(',') if f]
if not TEMPLATE_FILES:
TEMPLATE_FILES = ['/path/to/example.soy'] # Replace with a valid .soy file path
# Example 1: Compiling Soy templates to JavaScript
try:
# output_dir = '/tmp/js_templates'
# os.makedirs(output_dir, exist_ok=True) # Python 3 syntax
# CompileToJs(SOY_JAR_PATH, TEMPLATE_FILES, output_dir)
# print(f"Soy templates compiled to {output_dir}")
print("To compile: Uncomment and set SOY_JAR_PATH, TEMPLATE_FILES, and output_dir.")
print("Example: CompileToJs(SOY_JAR_PATH, TEMPLATE_FILES, '/tmp/js_templates')")
except Exception as e:
print(f"Failed to compile templates (expected if setup is not complete): {e}")
# Example 2: Rendering a Soy template
try:
renderer = Renderer(SOY_JAR_PATH, TEMPLATE_FILES)
# Assuming 'my.template.name' is a template defined in one of TEMPLATE_FILES
# and 'data' is a dictionary matching the template's parameters.
# rendered_html = renderer.render('my.template.name', {'param': 'value'})
# print(f"Rendered HTML: {rendered_html}")
print("To render: Uncomment and set SOY_JAR_PATH, TEMPLATE_FILES. Provide a template name and data.")
print("Example: renderer.render('my.template.name', {'param': 'value'})")
except Exception as e:
print(f"Failed to render template (expected if setup is not complete): {e}")
soy --version
Debug
Known issues
breakingThis 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`.fixUse a Python 2.x environment or migrate to a modern templating solution for Python 3.
affects: All versions (20121221) when used with Python 3.x
gotchaThe `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.fixEnsure 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`.
affects: All versions (20121221)
deprecatedThe project is abandoned, with the last release in 2012 and no further maintenance. It's not suitable for new projects or modern Python environments.fixConsider 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.
affects: All versions (20121221)
Upgrade
Version history
20121221latest on PyPI · released Jan 18, 2013
Audit
Dependencies
No dependency data recorded yet.