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 indented HTML to any file-like object, escaping what you pass through escape.

from io import StringIO

from hyperscribe import DocWriter, escape

output = StringIO()
doc, t, v = DocWriter(output).parts

with t.html(lang="en"):
    with t.body.main:
        t.h1(escape("Hello & welcome"))
        with t.ul:
            for name in ("one", "two"):
                t.li(escape(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.
  • Attribute values follow the same rules as content: literal strings, escaped strings and numbers are written verbatim.
  • doc(...) and tag content, as in t.p(...), write trusted LiteralString, __html__ objects, and numeric values verbatim while preserving indentation; escape and trust mark other strings as safe for them.
  • On Python 3.14 and newer, template strings (t"...") are accepted too: literal parts are trusted and interpolated values are escaped.
  • Output is streamed to anything with a write(str) method, or to a function.
  • Async templates write synchronously too: hyperscribe.streaming sends the page in chunks where the template chooses, and can stream slow parts out of order.
  • Fully typed, and supports Python 3.10 and newer.
  • No dependencies apart from typing_extensions for Python 3.10–3.13.

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
make doctest  # run the examples in 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.voids 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 going through doc.voids 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. DocWriter.__call__ and tag content have preliminary support for trusted content: LiteralString, SafeStr from escape and trust, objects implementing __html__ (such as MarkupSafe's Markup), and numeric values are written verbatim with indentation. Broader safe string support for CSS, JavaScript, or prepared markup, perhaps built on template strings, remains future work.

Status

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

Metadata

Release files for hyperscribe 0.6.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.6.0
File Size Uploaded Provenance Actions
hyperscribe-0.6.0.tar.gz 35.8 kB With provenance Details for hyperscribe-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 49.8 kB

Release files / hyperscribe-0.6.0.tar.gz

Download URL hyperscribe-0.6.0.tar.gz
Size 35.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1cf2f1a837a7f6c013cc9dd5b8bf1af6b86b112a0db482486bac27b32d8e8b40
BLAKE2b-256 checksum
How to use checksums
1a9bbb8fcb57ab8309b196032fb1499136b753f6468a8a41d5c4bed7df456af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 3, 2026.

Transparency log

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

Download URL hyperscribe-0.6.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
926480e65fe33b3443333e31045a853efd36f0074a9b716757fb2c38959977e6
BLAKE2b-256 checksum
How to use checksums
87fd46f8f94d269295af9f7518b089bc56ecbe27f830441deabd71acca13dfbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 3, 2026.

Transparency log

Security for hyperscribe 0.6.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hyperscribe-0.6.0.tar.gz

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 Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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