
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
pytera
Advanced tools
A fast, Python-native templating engine powered by Rust's Tera library. PyTera brings the power and performance of Tera templates to Python applications through PyO3 bindings.
Install PyTera from PyPI:
pip install pytera
Or using uv:
uv add pytera
import os
from pytera import PyTera
template_dir = os.path.join(os.path.dirname(__file__), "templates")
tera = PyTera(f"{template_dir}/*.html")
result = tera.render_template("basic_variables.html", name="Alice", age=30)
print(result) # Hello Alice! You are 30 years old.
ℹ️ Glob pattern tips: The current templates live directly under
templates/, soPyTera(f"{template_dir}/*.html")works. If you reorganize templates into nested subdirectories, switch toPyTera(f"{template_dir}/**/*.html")to load them recursively.
tera = PyTera("templates/*.html")
result = tera.render_template(
"basic_variables.html",
name="Alice",
age=30,
)
print(result) # Hello Alice! You are 30 years old.
ℹ️ Glob pattern tips: Current templates live directly under
templates/, soPyTera(f"{template_dir}/*.html")works. If you organize templates into nested subdirectories later, switch toPyTera(f"{template_dir}/**/*.html")to load them recursively.
<!-- templates/basic_variables.html -->
Hello {{ name }}! You are {{ age }} years old.
user = {"name": "Bob", "is_admin": True}
result = tera.render_template("conditionals.html", user=user)
print(result) # Welcome, Administrator Bob!
<!-- templates/conditionals.html -->
{% if user.is_admin %}
Welcome, Administrator {{ user.name }}!
{% else %}
Hello, {{ user.name }}!
{% endif %}
items = [
{"name": "Apple", "price": 1.50},
{"name": "Banana", "price": 0.75},
{"name": "Cherry", "price": 2.25},
]
result = tera.render_template("loops.html", items=items)
print(result)
<!-- templates/loops.html -->
<ul>
{% for item in items %}
<li>{{ item.name }}: {{ item.price | round(precision=2) }}</li>
{% endfor %}
</ul>
data = {
"text": "hello world",
"missing": None,
"list": ["apple", "banana", "cherry", "date"],
}
result = tera.render_template("filters.html", **data)
print(result)
<!-- templates/filters.html -->
<p>Uppercase: {{ text | upper }}</p>
<p>Length: {{ text | length }}</p>
<p>Default: {{ missing | default(value="N/A") }}</p>
<p>Slice: {{ list | slice(start=1, end=3) | join(sep=", ") }}</p>
<!-- templates/base.html -->
<!DOCTYPE html>
<html>
<head>
<title>{% block title %}Default Title{% endblock %}</title>
</head>
<body>
<header>
<h1>My Website</h1>
</header>
<main>
{% block content %}{% endblock %}
</main>
<footer>
<p>© 2023</p>
</footer>
</body>
</html>
<!-- templates/child.html -->
{% extends "base.html" %}
{% block title %}Home Page{% endblock %}
{% block content %}
<h2>Welcome to {{ site_name }}</h2>
<p>This is the home page content.</p>
{% if user %}
<p>Hello, {{ user.name }}!</p>
{% endif %}
{% endblock %}
import os
from flask import Flask, render_template
from pytera import PyTera
template_dir = os.path.join(os.path.dirname(__file__), "..", "templates")
tera = PyTera(f"{template_dir}/*.html")
app = Flask(__name__, template_folder=os.path.abspath(template_dir))
@app.route("/")
def index():
return tera.render_template(
"child.html",
site_name="example",
user={"name": "David"},
)
@app.route("/child")
def child():
return render_template(
"child.html",
site_name="example",
user={"name": "David"},
)
For a complete working example with additional routes (/basic_variables, /conditionals, /filters, /loops), see examples/app.py.
The templates rendered in examples/app.py cover the core pieces of Tera syntax:
Hello {{ name }}! You are {{ age }} years old.
{% if user.is_admin %}
Welcome, Administrator {{ user.name }}!
{% else %}
Hello, {{ user.name }}!
{% endif %}
<ul>
{% for item in items %}
<li>{{ item.name }}: {{ item.price | round(precision=2) }}</li>
{% endfor %}
</ul>
<p>Uppercase: {{ text | upper }}</p>
<p>Length: {{ text | length }}</p>
<p>Default: {{ missing | default(value="N/A") }}</p>
<p>Slice: {{ list | slice(start=1, end=3) | join(sep=", ") }}</p>
{% extends "base.html" %}
{% block title %}Home Page{% endblock %}
{% block content %}
<h2>Welcome to {{ site_name }}</h2>
{% if user %}
<p>Hello, {{ user.name }}!</p>
{% endif %}
{% endblock %}
For more template features—such as macros, tests, and custom filters—consult the Tera documentation.
PyTera provides detailed error messages for common issues:
# Clone the repository
git clone https://github.com/un4gt/pytera.git
cd pytera
# Install development dependencies
uv sync --dev
# Build the package
maturin develop
# Run tests
pytest
# Run all tests
pytest
# Run with coverage
pytest --cov=pytera --cov-report=html
# Format code
cargo fmt
black src/
# Lint code
cargo clippy
flake8 src/
We welcome contributions! Please see our Contributing Guide for details.
# Install development dependencies
uv sync --dev
# Install pre-commit hooks
pre-commit install
# Build and test
maturin develop
pytest
PyTera is licensed under the MIT License. See LICENSE for details.
See CHANGELOG.md for version history.
FAQs
A fast, Python templating engine powered by Rust's Tera library
We found that pytera demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.