Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

PyTempl

Build HTML user interfaces in Python.

Introduction

PyTempl is a DSL that lets you build HTML components as Python objects, offering a clean, component-based approach that avoids the complexities of traditional templating engines. Create reusable components that generate HTML fragments to build complex views, pages, or even entire web applications, all within your Python workflow.

Getting Started

Installation:

pip install pytempl  

Simple Example:

from pytempl.tags.html import H1, Div, P
from pytempl import render

page = Div(_class="container")(
    H1()("My Awesome Page"),
    P()("This is a paragraph of text.")
)

print(render(page))

This will output neatly formatted HTML.

Advanced Example 1: Dynamic Content and Components

from pytempl.tags.html import Li, Span, Ul
from pytempl import render

items = ["apple", "banana", "cherry"]
item_list = Ul()(Li()(item) for item in items)

name = "Alice"
greeting = Span()(f"Hello, {name}!")

print(render(Div()(greeting, item_list)))

This demonstrates creating dynamic content and nesting components. The output will be an HTML <div> containing a greeting and the unordered list of fruits.

Advanced Example 2: HTMX Support

from pytempl.tags.html import Div, Button, Img
from pytempl import render

click_to_load = Div(id="replace_me")(
    Button(
        _class="btn primary",
        hx_get="/example/?data=1",
        hx_target="#replace_me",
        hx_swap="outerHTML",
    )(
        "Load More Data...",
        Img(_class="htmx-indicator", src="/img/bars.svg", alt="Loading..."),
    )
)

print(render(click_to_load))

Backwards Compatibility Note

This project is under active development and has not yet reached v1.0.0. This means that while we are working hard to build the best possible package, we may need to make changes that affect how your code works.

Version Stability:

  • Minor Version Updates (e.g., 0.1.x -> 0.2.x): These updates may introduce breaking changes as we refine and improve the package's functionality and APIs.
  • Patch Version Updates (e.g., 0.1.1 -> 0.1.2): These updates will maintain compatibility within the same minor version and generally include bug fixes or small enhancements.

To avoid unexpected disruptions, it is recommended to pin your dependency to a specific minor version (v0.x) and carefully review release notes before upgrading to a new minor version.

We appreciate your understanding and welcome feedback as we work towards a stable and robust v1.0.0!

License

This project is licensed under the BSD-2-Clause License

Metadata

Release files for pytempl 0.2.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytempl 0.2.10
File Size Uploaded
pytempl-0.2.10.tar.gz 61.5 kB Details

Built distribution (wheel)

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

Total release size: 169.2 kB

Release files / pytempl-0.2.10.tar.gz

Download URL pytempl-0.2.10.tar.gz
Size 61.5 kB
Tags Source
SHA-256 checksum
How to use checksums
29ef943ad556140556baae273665cd30d202dc3623d64c2a17b11ab440ec355f
BLAKE2b-256 checksum
How to use checksums
6a17fce892c48e7f3cfc3c21c61dcc9a9a9cc943e71e376df71e3c14ea397d1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14

Release files / pytempl-0.2.10-py3-none-any.whl

Download URL pytempl-0.2.10-py3-none-any.whl
Size 107.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
511fe4471e81a80c724e25414c3922e30d56b4802a52df56856e024f6e4accc2
BLAKE2b-256 checksum
How to use checksums
aefe05d7862890371746da2c55f9a193296e4262b95a26376e15d9c1e41da969
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.14
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