Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
Python template engine libraries render HTML or text by filling a template with data. An engine either compiles templates that embed Python expressions or uses a restricted syntax such as Mustache or Liquid that keeps logic in the data. These libraries let web servers, code generators, and email tools build output from shared templates.
Popularity
Jinja has the most monthly downloads in this comparison, at 721.2M.
def compose_initial_LLM_messages_with_templates(
system_template_name: str,
user_template_name: str = None,
base_module_folder: str = None,
rendering_configs: dict = {},
) -> list:
"""
Composes the initial messages for the LLM model call, under the assumption that it always involves
a system (overall task description) and an optional user message (specific task description).
These messages are composed using the specified templates and rendering configurations.
"""
# ../ to go to the base library folder, because that's the most natural reference point for the user if base_module_folder is None:
sub_folder = "../prompts/"
else:
sub_folder = f"../{base_module_folder}/prompts/"
base_template_folder = os.path.join(os.path.dirname(__file__), sub_folder)
system_prompt_template_path = os.path.join(
base_template_folder, f"{system_template_name}"
)
user_prompt_template_path = os.path.join(
base_template_folder, f"{user_template_name}"
)
messages = []
messages.append(
{
"role": "system",
"content": chevron.render(
open(
system_prompt_template_path, "r", encoding="utf-8", errors="replace"
).read(),
rendering_configs,
),
}
)
# optionally add a user message if user_template_name is not None:
messages.append(
{
"role": "user",
"content": chevron.render(
open(
user_prompt_template_path,
"r",
encoding="utf-8",
errors="replace",
).read(),
rendering_configs,
),
}
)
return messages
import liquid
print(liquid.render("Hello, {{ you }}!", {"you": "World"}))
FAQ
Jinja suits most applications, with template inheritance, macros, async rendering, and a sandbox. Mako suits templates that embed Python expressions and code. Chevron and Pystache suit logic-less Mustache templates.
Jinja is a standalone template engine with loaders, macros, inheritance, optional async rendering, and a separate sandbox. HTML autoescaping must be configured explicitly.
No. Resource limits are still needed to contain excessive CPU or memory usage.
Mako is a templating language with embedded Python expressions and inheritance. Alembic uses it to generate migration files.
No. Tornado template generation returns bytes synchronously, even inside an async handler. Jinja supplies a separate asynchronous render method.
For coding agents
Found your template engine library? Help your agent use it.
Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.