A modern html templating library for python
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.
- Templates are optimised and compiled into Python leading to microsecond long render times.
- 5x faster than Jinja, 50x faster the django
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>
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>