Skip to main content

kara-templater

An ASS karaoke template engine rewritten in Python and C++. It runs without Aegisub or Lua.

The package keeps the karaoke templater's ASS template format, $variables, modifiers, and helper functions. Expressions inside !…! and code lines use Python. Lua code in existing templates must be rewritten manually; there is no Lua compatibility interpreter.

Installation

Requires Python 3.12 or newer. Binary wheels target CPython 3.12–3.14 on Linux x86-64 (glibc 2.28+) and Windows 10+ x64. They include the native library dependencies; no compiler or MSYS2 installation is needed to use a wheel.

python -m pip install kara-templater

Install the fonts specified by your subtitle styles. Missing fonts use system font fallback, and different fonts can change the layout.

Build from source on Linux

Install a C/C++ toolchain and native dependencies.

Arch Linux:

sudo pacman -S --needed base-devel python python-pip autoconf automake libtool nasm \
  freetype2 harfbuzz fribidi fontconfig libpng

Debian / Ubuntu, with Python 3.12+:

sudo apt install build-essential python3-dev python3-venv autoconf automake \
  libtool nasm pkg-config libfreetype-dev libharfbuzz-dev libfribidi-dev \
  libfontconfig-dev libpng-dev

From the project directory:

python -m venv .venv
. .venv/bin/activate
python -m pip install .

Build from source on Windows

Use 64-bit Python from python.org and MSYS2. In the MSYS2 UCRT64 shell, install the native toolchain:

pacman -Syu
pacman -S --needed patch mingw-w64-ucrt-x86_64-gcc \
  mingw-w64-ucrt-x86_64-pkgconf mingw-w64-ucrt-x86_64-nasm \
  mingw-w64-ucrt-x86_64-freetype mingw-w64-ucrt-x86_64-harfbuzz \
  mingw-w64-ucrt-x86_64-fribidi

Restart the shell and complete the update if MSYS2 requests it. Then, in PowerShell at the project directory, build and install a wheel. Adjust the MSYS2 path if it is not installed at C:\msys64.

$env:Path = "C:\msys64\ucrt64\bin;C:\msys64\usr\bin;$env:Path"
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install delvewheel
python tools/collect_licenses.py
python -m pip wheel . --no-deps --wheel-dir dist
python -m delvewheel repair --strip --no-mangle libharfbuzz-0.dll --wheel-dir wheelhouse (Get-ChildItem dist\*.whl).FullName
python -m pip install --no-index --find-links wheelhouse kara-templater

The repaired wheel bundles the required DLLs so it can run without MSYS2 on the destination machine. Windows uses the system DirectWrite/GDI font provider.

Command line

kara-templater input.ass output.ass
python -m kara_templater input.ass output.ass

Try the included example from a source checkout:

kara-templater examples/karaoke.ass output.ass

To correct horizontal coordinates for the video's actual dimensions:

kara-templater input.ass output.ass --video-size 1920 1080

Templates are ASS Comment events. Put the template type and modifiers in the Effect field. For example:

  • Effect: template syl noblank
  • Text: !retime("syl")!{\an5\pos($scenter,$smiddle)\fad(50,80)}

For lyrics such as {\k50}你{\k50}好, this generates one positioned effect event per nonblank syllable.

The output preserves templates, turns processed lyrics into comments with Effect karaoke, and marks generated events with Effect fx. Running the engine again removes old fx events and regenerates them.

Python API

from kara_templater import Document, Style, apply_templates, text_extents

source = Document.load("input.ass")
result = apply_templates(source)
result.save("output.ass")

width, height, descent, external_leading = text_extents(
    Style(fontname="Noto Sans CJK SC", fontsize=48), "你好"
)

apply_templates returns a new document without modifying its input. Document.parse(text) and result.dumps() support in-memory use.

Templates

Type Behavior
template syl, or no explicit type Generate effects per syllable, including the empty syllable at index 0; usually combined with noblank
template char / template syl char Generate effects per Unicode code point, retaining syllable timing
template line Concatenate the per-syllable template into one complete effect event
template pre-line Prefix a complete event; use the same identifier to merge it with a line template
template furi Generate effects for furigana
code once / line / syl / furi Execute Python statements in that scope; defaults to once

Modifiers include all, repeat N / loop N, notext, keeptags, noblank, multi, fx NAME, and fxgroup NAME. Templates match their own style by default; all matches every style. Unknown modifiers, variables, and execution errors report the template event number instead of being silently ignored.

  • \k, \K, \kf, \ko: syllable duration in centiseconds.
  • \-NAME: inline effect name, inherited by subsequent syllables.
  • # / #: continue the preceding syllable; multi runs the template separately for each highlight.
  • 漢|かん / 漢|かん: separate base text from furigana. A furigana prefix ! starts a new group; < allows spillback to the left. Full-width prefixes are also accepted. A missing furigana style is created as STYLE-furigana at half the base font size.

Variables and execution environment

$variables are case-insensitive:

  • Line timing and indices: $lstart, $lend, $ldur, $lmid, $li, $syln.
  • Syllable timing and indices: $sstart, $send, $sdur, $skdur, $smid, $si.
  • Layout: prefix l or s to left, center, right, width, top, middle, bottom, height, x, or y.
  • Current-scope aliases: $start, $end, $dur, $kdur, $mid, $i, and unprefixed layout variables.
  • Other values: $layer, $style, $actor, $margin_l, $margin_r, $margin_v, $margin_t, $margin_b.

Expressions and code share Python variables. The environment provides math, random, meta, styles, orgline, line, syl, basesyl, j, maxj, fxgroup, and text_extents. line is the current mutable output event; in a code template it is the source lyric event. syl is a dictionary with attribute access.

Example Effect and Text pairs:

code once                  → amplitude = 12
code line                  → fxgroup["spark"] = orgline.actor == "solo"
template syl repeat 3      → !retime("syl")!{\an5\pos(!$x + amplitude * j!,$y)}

An expression returning None produces an empty string. Integral floating-point values are written without a trailing .0.

Helpers

  • retime(mode, addstart=0, addend=0): modes are syl, presyl, postsyl, line, preline, postline, start2syl, syl2end, sylpct, and set / abs. Offsets are milliseconds, except that sylpct uses percentages of syllable duration. Timing is based on the current line, so consecutive calls use the previously modified times.
  • relayer(layer), restyle(style): modify the current output event.
  • maxloop(count) / maxloops(count), loopctl(j, count): control template loops dynamically.
  • remember(name, value, decorator=None), recall(name, default=None), remember_if(name, value, condition, decorator=None): store and retrieve values. The optional decorator is a Python function mapping a name to a memory key.
  • remember_line, remember_syl, remember_basesyl: isolate remembered values by source event, current syllable, or base syllable.

Limitations and safety

  • Only process trusted subtitles. Python expressions and code have the permissions of the current process. This is not a sandbox. Template iteration and output limits cannot stop arbitrary Python code from looping forever or performing malicious operations.
  • The defaults are 10,000 iterations per template loop and 100,000 output events. The Python API accepts max_iterations and max_output_lines to change these limits.
  • Only ASS v4.00+ is supported, not legacy SSA styles. Extra fields, unknown sections, and attachments are preserved, but byte-for-byte formatting is not guaranteed.
  • Layout targets single-line karaoke using the base style. It does not simulate automatic wrapping, event collisions, inline style overrides, \pos / \move, or drawing geometry. text_extents supports \N hard breaks; syllable layout is not multiline-aware.
  • text_extents returns logical advance width, font height, and descent, not visible glyph bounds. It preserves edge spaces and measures braces literally. External leading is always 0. Pixel-identical results across fonts, platforms, or Aegisub's native font interfaces are not guaranteed.
  • No GUI, video/audio processing, Automation plugin interface, or other Aegisub features are included.

Metadata

Release files for kara-templater 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kara-templater 0.1.0
File Size Uploaded
kara_templater-0.1.0.tar.gz 390.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for kara-templater 0.1.0
File
kara_templater-0.1.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
kara_templater-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64 Details
kara_templater-0.1.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
kara_templater-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
kara_templater-0.1.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
kara_templater-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details

Total release size: 26.9 MB

Release files / kara_templater-0.1.0.tar.gz

Download URL kara_templater-0.1.0.tar.gz
Size 390.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4741910d0b278ef42f6147dfd9cd72194fbc905b4c842db96590ada136a10251
BLAKE2b-256 checksum
How to use checksums
e8808be4e5b0792ce36368f34350eb29ccf5077d1b41957cc5e6275e9a704799
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / kara_templater-0.1.0-cp314-cp314-win_amd64.whl

Download URL kara_templater-0.1.0-cp314-cp314-win_amd64.whl
Size 5.5 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
6d1fb9959e1b5f2d5ad981c27a02a25d07c6c626af6eb6d70034acd21fac1242
BLAKE2b-256 checksum
How to use checksums
fdc6a7ead473d276a5c75d2817deef2ee4157efcb3db08ca84e459164c203e5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / kara_templater-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl

Download URL kara_templater-0.1.0-cp314-cp314-manylinux_2_28_x86_64.whl
Size 3.4 MB
Tags CPython 3.14 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
521407906410ce0d452556a39ec8a414f7c12eba5b21b43111b853686605d1bd
BLAKE2b-256 checksum
How to use checksums
4d058787e07be427f3643e3e18bc860758110711826d8d5822b9e0b6c8ecef13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / kara_templater-0.1.0-cp313-cp313-win_amd64.whl

Download URL kara_templater-0.1.0-cp313-cp313-win_amd64.whl
Size 5.4 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
8c1e9c2f3c1939ccc028566bfdf3fa305e957d6311d19e8787971bbe38bd0099
BLAKE2b-256 checksum
How to use checksums
a713dac32a8c6d6e78e829463986ab096ed581b397259d14f7bd1583af29f964
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / kara_templater-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL kara_templater-0.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
Size 3.4 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
bdc3c716bd44377f0681746868e591c64e083c0b743579fa378570a53ae229bc
BLAKE2b-256 checksum
How to use checksums
efb299817337302dd134923568a7246c6fb4aa07249e7ed89e735f62093a3bfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / kara_templater-0.1.0-cp312-cp312-win_amd64.whl

Download URL kara_templater-0.1.0-cp312-cp312-win_amd64.whl
Size 5.4 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
0573600b2379d3d1e3333aed4ad7e614d632226134256cbf8d8853992ea5ff55
BLAKE2b-256 checksum
How to use checksums
f87f8f393f0ca2b0aefbe45dff86306c3453e6dd6daf989a6b18556e12a5ef4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / kara_templater-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL kara_templater-0.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 3.4 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1362a349b877932b6bc5e666713810a77e8bd98b4ad71e6d62f5e38d5d5ddee6
BLAKE2b-256 checksum
How to use checksums
e1dab18bb974e00693fc0d9683eb47a1390cbaefd34dbee9e277e00658420bb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.1

7 release files

This release

0.1.0 This release

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page