Skip to main content

hyperscribe

A small, dependency-free HTML templating engine for Python. You write markup as ordinary Python code with context managers, and hyperscribe streams escaped, indented HTML to any file-like object.

from io import StringIO

from hyperscribe import DocWriter

output = StringIO()
doc = DocWriter(output)

with doc.html(lang="en"):
    with doc.body.main:
        doc.h1("Hello & welcome")
        with doc.ul:
            for name in ("one", "two"):
                doc.li(name)

print(output.getvalue())
<html lang="en">
  <body>
    <main>
      <h1>Hello &amp; welcome</h1>
      <ul>
        <li>one</li>
        <li>two</li>
      </ul>
    </main>
  </body>
</html>

Features

  • Templates are plain Python: use loops, functions, and @contextmanager layouts.
  • Text and attribute values are escaped by default.
  • Output is streamed to anything with a write(str) method.
  • No dependencies, fully typed, and supports Python 3.10 and newer.

Installation

pip install hyperscribe

Documentation

Full documentation is available at https://septatrix.github.io/hyperscribe/.

Development

make sync     # install dependencies
make check    # lint, type-check, check formatting, and test
make format   # format the code with ruff
make docs     # build the documentation

Run make help to list all targets. Use uv run sphinx-autobuild docs docs/_build/html to preview the docs while editing.

The benchmarks compare hyperscribe with other Python HTML templating libraries using pytest-benchmark. Their dependencies live in the optional benchmarks dependency group and need Python 3.14:

uv run --group benchmarks pytest benchmarks

Releasing

The version is derived from git tags by hatch-vcs. To release, publish a GitHub release whose tag is v plus the version, such as v0.2.0. The Publish workflow builds the package and uploads it to PyPI through trusted publishing. Copy the files in contrib/workflows/ to .github/workflows/ once, using a credential that may edit workflows.

Roadmap

These gaps showed up when porting real Jinja and bottle templates to hyperscribe. Attribute handling, content conversion, comments, doc.void_tag for void elements, and the guide's loop idioms have been dealt with since. Two larger items remain.

  • Element registry. hyperscribe does not know anything about individual elements. A registry with metadata per element should cover the following:
    • Void elements such as <br> and <img> should be written without calling doc.void_tag explicitly.
    • Whitespace-sensitive elements such as <pre> and <textarea> should switch to inline mode automatically. Today the caller has to know to use doc.inline().
    • The contents of <style> and <script> should be written verbatim.
    • The set of permitted attributes could be checked.
  • Trusted content. Escaping text by default is intended. What is missing is a way to mark content as already safe other than write_raw, for example CSS, JavaScript or prepared markup. The idea is a safe string type, either MarkupSafe's Markup or a custom implementation, perhaps built on template strings (t"").

Status

hyperscribe is in early development and its API may change between minor releases.

Metadata

Release files for hyperscribe 0.2.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 hyperscribe 0.2.0
File Size Uploaded
hyperscribe-0.2.0.tar.gz 14.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hyperscribe 0.2.0
File Interpreter ABI Platform
hyperscribe-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.5 kB

Release files / hyperscribe-0.2.0.tar.gz

Download URL hyperscribe-0.2.0.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
38e40014f5391c0233a0fbf7a92013dd0e2d84d877be2a6acb01f7ad3d226966
BLAKE2b-256 checksum
How to use checksums
ebb7b9c4c431c4458e9783f6f8fb5cb811eef5a1588daab51413af3d459f7181
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 1, 2026.

Transparency log

Release files / hyperscribe-0.2.0-py3-none-any.whl

Download URL hyperscribe-0.2.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2e14816b9be3e6ab787ebf7e37918306738b0953bff863e8db734d4c358b164
BLAKE2b-256 checksum
How to use checksums
0402fbfe154152311125e1ea72171a7f32140c07efcbe9f97758092170a446e5
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 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 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