Skip to main content

Python template engine for HTML, terminal, and streaming — with framework integration

Project description

)彡 Kida

PyPI version Build Status Python 3.14+ License: MIT

A template engine that compiles to Python AST, renders to HTML/terminal/markdown, and scales across cores on free-threaded Python.

Installation

pip install kida-templates

Requires Python 3.14+. Zero runtime dependencies.


Render Anywhere

One template syntax, four surfaces.

HTML

from kida import Environment, FileSystemLoader

env = Environment(loader=FileSystemLoader("templates/"))
template = env.get_template("page.html")
html = template.render(title="Hello")

Terminal

from kida.terminal import terminal_env

env = terminal_env()
template = env.from_string("""
{{ "Deploy Status" | bold | cyan }}
{{ hr(40) }}
{% for svc in services %}
{{ svc.name | pad(20) }}{{ svc.status | badge }}
{% end %}
""")
print(template.render(services=[
    {"name": "api", "status": "pass"},
    {"name": "worker", "status": "fail"},
]))

Markdown

from kida.markdown import markdown_env

env = markdown_env()
template = env.from_string("# {{ title }}\n\n{{ body }}")
md = template.render(title="Report", body="All tests passed.")

CI Reports (GitHub Action)

Turn pytest, coverage, ruff, and other tool output into step summaries and PR comments.

- uses: lbliii/kida@v0.3.3
  with:
    template: pytest
    data: results.xml
    data-format: junit-xml
    post-to: step-summary,pr-comment

Built-in templates for pytest, coverage, ruff, ty, jest, gotest, and sarif. Full action docs →


Key Features

Template Inheritance

base.html:

<!DOCTYPE html>
<html>
<body>
    {% block content %}{% end %}
</body>
</html>

page.html:

{% extends "base.html" %}
{% block content %}
    <h1>{{ title }}</h1>
{% end %}
Components & Named Slots
{% def card(title) %}
<article class="card">
  <h2>{{ title }}</h2>
  <div class="actions">{% slot header_actions %}</div>
  <div class="body">{% slot %}</div>
</article>
{% end %}

{% call card("Settings") %}
  {% slot header_actions %}<button>Save</button>{% end %}
  <p>Body content.</p>
{% end %}
Pattern Matching & Null Safety
{% match status %}
{% case "active" %}
    Active user
{% case "pending" %}
    Pending verification
{% case _ %}
    Unknown status
{% end %}

{# Null coalescing #}
{{ user.nickname ?? user.name ?? "Anonymous" }}

{# Optional chaining #}
{{ config?.database?.host }}

{# Safe pipeline — stops on None #}
{{ data ?|> parse ?|> validate ?|> render }}
Streaming & Block Rendering
# Stream chunks as they render (chunked HTTP, SSE)
for chunk in template.render_stream(items=large_list):
    response.write(chunk)

# Render a single block (HTMX partials)
html = template.render_block("content", title="Hello")

# Compose layouts with pre-rendered blocks
html = layout.render_with_blocks({"content": inner_html}, title="Page")
Regions — Parameterized Blocks
{% region sidebar(current_path="/") %}
  <nav>{{ current_path }}</nav>
{% end %}

{{ sidebar(current_path="/about") }}

Regions are blocks (for render_block()) and callables (for inline use). Ideal for HTMX OOB swaps and framework integration.

Compile-Time Optimization
# Pass static data at compile time — kida folds constants,
# eliminates dead branches, and evaluates pure filters
template = env.from_string(source, static_context={
    "site": site_config,
    "settings": app_settings,
})

# Only dynamic data needed at render time
html = template.render(page_title="Home", items=page_items)

67 pure filters evaluated at compile time. Dead {% if debug %} branches removed entirely. Component inlining for small defs with constant args.

Use kida render template.html --explain to see which optimizations are active.

Free-Threading

All public APIs are safe under PYTHON_GIL=0 (Python 3.14t, PEP 703):

  • Templates compile to immutable AST — no shared mutable state
  • Rendering uses thread-local StringBuilder — no contention
  • Environment uses copy-on-write for configuration changes
  • LiveRenderer.update() is thread-safe with internal locking

Module declares GIL independence via _Py_mod_gil = 0. Rendering scales linearly with cores.

Framework Integration

Drop-in adapters for Flask, Starlette/FastAPI, and Django:

# Flask
from kida.contrib.flask import KidaFlask
kida = KidaFlask(app)

# Starlette / FastAPI
from kida.contrib.starlette import KidaStarlette
templates = KidaStarlette(directory="templates")

# Django
TEMPLATES = [{"BACKEND": "kida.contrib.django.KidaDjango", ...}]
CLI
# Render a template
kida render template.txt --data context.json
kida render dashboard.txt --mode terminal --width 80 --color truecolor

# Show which compiler optimizations are active
kida render template.html --explain

# Check all templates for syntax errors
kida check templates/

# Strict mode: require explicit end tags ({% endif %} not {% end %})
kida check templates/ --strict

# Validate macro call sites against signatures
kida check templates/ --validate-calls

# Accessibility and type checking
kida check templates/ --a11y --typed

# Auto-format templates
kida fmt templates/

The Bengal Ecosystem

Kida is part of a pure-Python stack built for 3.14t free-threading.

ᓚᘏᗢ Bengal Static site generator Docs
∿∿ Purr Content runtime
⌁⌁ Chirp Web framework Docs
=^..^= Pounce ASGI server Docs
)彡 Kida Template engine Docs
ฅᨐฅ Patitas Markdown parser Docs
⌾⌾⌾ Rosettes Syntax highlighter Docs
ᓃ‿ᓃ Milo Terminal UI framework Docs

License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kida_templates-0.3.4.tar.gz (451.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kida_templates-0.3.4-py3-none-any.whl (341.0 kB view details)

Uploaded Python 3

File details

Details for the file kida_templates-0.3.4.tar.gz.

File metadata

  • Download URL: kida_templates-0.3.4.tar.gz
  • Upload date:
  • Size: 451.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kida_templates-0.3.4.tar.gz
Algorithm Hash digest
SHA256 a14cdfab64c8fb71d7c1dd59199a2add50bbaa5f8e0f8c84c208b58b5e353a1c
MD5 c35aa1015a14d103a2f6dfe2a2c660ff
BLAKE2b-256 e180bd7244faca4169d93a0a74942b8b082b11af3ae759b9725d6f808ea5ad5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kida_templates-0.3.4.tar.gz:

Publisher: python-publish.yml on lbliii/kida

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kida_templates-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: kida_templates-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 341.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for kida_templates-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 21c188d533e8d39c494d16227a2da7271cbb8089e25a2cedb6df0f1a5ec2e5b9
MD5 0c416ff67a23b7383a185257a976f588
BLAKE2b-256 46e6a8de9271b6f0df714a82c421af5ed92f98ff592edafd03f1c2ebc945a11f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kida_templates-0.3.4-py3-none-any.whl:

Publisher: python-publish.yml on lbliii/kida

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page