Generate native python functions from HTML templates
Project description
Tempered (Beta)
Convert html templates into native python components
pip install tempered
Documentation | PyPi | Github |
---|
Features
- Fast
- Roughly 5x faster than jinja, 50x faster than django
- Scoped CSS
- CSS is scoped per component
- Components
- Each template is it's own components and can call other components
- Layouts
- Templates can inherit layouts, based on jinja2's implementation
- Type Checked
- The compiled components can be checked by static analysers such as mypy
- Intelisense
- Components have intelisense support
Example
<!-- templates/Image.html -->
{% param src: str %}
{% param alt: str = "" %}
<img src="{{src}}" alt="{{alt}}">
<style>
img {
width: 100px;
height: 100px;
}
</style>
from tempered import Tempered
tempered = Tempered()
tempered.add_template_folder("./templates")
components = tempered.build()
print(components.Image(
src="/example.png",
alt="Example Post",
))
<img alt="Example Post" src=/example.png class=image-83dc><style>img.image-83dc{width:100px;height:100px}</style>
Compiled
Tempered is runtime compiled and loaded, this provides increased performance as well as intelisense and type checking.
# This file is dynamicly generated when you build the templates
from __future__ import annotations as __annotations
import typing as __typing
from tempered._internals import escape as __escape
def Image(*, src: str, alt: str = '', with_styles: bool = True, **kwargs: __typing.Any) -> str:
__css = 'img.image-83dc{width:100px;height:100px}'
__html = f' <img alt="{__escape(alt)}" src="{__escape(src)}" class=image-83dc>'
if with_styles and __css:
__html += '<style>' + (__css + '</style>')
return __html
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tempered-0.8.0.tar.gz
(31.8 kB
view hashes)
Built Distribution
tempered-0.8.0-py3-none-any.whl
(34.3 kB
view hashes)