Skip to content

Ben-Brady/tempered

Repository files navigation

Tempered Banner

A modern html templating library for python

Test Package version Supported Python versions


Documentation: https://Ben-Brady.github.io/tempered/

Source Code: https://github.com/Ben-Brady/tempered

pip install tempered

Tempered is templating library designed around HTML and type safety.

  • Fast: Sub-millisecond render times.
  • Scoped and Bundled CSS: CSS is scoped per file and then bundled together into a single stylesheet per page
  • Native Preprocesser Support: Native support for Sass
  • Component Based: Each template is a components and can call other components
  • Layouts: Templates can use layouts, based on jinja2's implementation
  • Dynamically Typed: Optional dynamic type information can be built with components for better intelisense.

Lightning Fast

  • Templates are optimised and compiled into Python leading to microsecond long render times.
  • 5x faster than Jinja, 50x faster the django
Full Page Benchmark Partials Benchmark Static Page Benchmark

Native CSS

CSS is scoped per componenet and bundled together into a single stylesheet.

<div>
  <img src="https://picsum.photos/320/180" alt="Example Post">
</div>

<style lang="sass">
  div {
    box-sizing: content-box;
    width: fit-content;
    overflow: hidden;

    border-radius: 1rem;
    border: .15rem solid black;

    img {
      height: auto;
      width: 10rem;
    }
  }
</style>

Example

from tempered import Tempered

tempered = Tempered("./templates")
html = tempered.render_template("image.html",
    src="/example.png",
    alt="Example Post",
)
print(html)
<!-- templates/Image.html -->
{% param src: str %}
{% param alt: str = "" %}

<img src="{{src}}" alt="{{alt}}">

<style>
    img {
        width: 100px;
        height: 100px;
    }
</style>
<img alt="Example Post" src="/example.png" class=image-83dc><style>img.image-83dc{width:100px;height:100px}</style>