PyHTML-HTMX 
HTMX integration for PyHTML - to build dynamic, hypermedia-driven web applications with only Python, Flask, optionally WebComponents and absolutely no Javascript.
Features
- Type-safe with full editor autocomplete
- All 35 HTMX attributes listed from HTMX's web-type document
- Literal types for (the one set of) enum values (e.g.:
swap="innerHTML") - Comprehensive documentation in docstrings also from the web-types.
- Works well with Flask and pyHtml see snippet.
Installation
From GitHub
pip install git+https://github.com/YlanAllouche/pyhtml-htmx.git
Local Development
git clone https://github.com/YlanAllouche/pyhtml-htmx.git
cd pyhtml-htmx
pip install -e . # --break-system-packages
Usage
The htmx() Helper Function
The hx() function creates HTMX attributes with a clean, intuitive API. Note that you use the attribute names without the hx_ prefix inside the function since it's already the name of the function.
Type Safety
The htmx() function provides full type hints with Literal types for (the one set of) enumerated values:
# 'swap' parameter uses Literal type - editor will suggest valid values
**hx(
swap="innerHTML" # Shown as valid
# swap="invalid" # LSP error in editor
)
Basic Flask example
import pyhtml as p
from pyhtml_htmx import hx
@app.route("/")
def index():
return p.html(
p.head(
p.title("HTMX App"),
p.script(src="https://unpkg.com/htmx.org@2.0.3")
),
p.body(
p.button(
"Click me",
**hx(post="/clicked", swap="outerHTML")
)
)
)
@app.route("/clicked", methods=["POST"])
def clicked():
return p.div("Button clicked")
Future Potential Enhancements
- Direct attribute support:
div("content", get="/url")- through monkey-patching
- or upstream integration
- either by
- supporting htmx directly
- or providing a hook for extra universal attributes
- at which point other libraries like Alpine could also be easily added
External documentation and dependencies
- PyHTML Documentation
- PyHTML Enhanced by Maddy Guthridge
Metadata
Release files for pyhtml-htmx 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyhtml_htmx-0.1.0.tar.gz | 8.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyhtml_htmx-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.5 kB
Release files / pyhtml_htmx-0.1.0.tar.gz
| Download URL | pyhtml_htmx-0.1.0.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
abb8a815a469acca322ecbdfdd0a7f4289cd9be748201b52b561f8249a2fa5ac
|
|
BLAKE2b-256 checksum How to use checksums |
7923ac33673c39456482d2a6cc4c0c91b4ecf37c6b9f2c5323fb6800208b3a5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pyhtml_htmx-0.1.0-py3-none-any.whl
| Download URL | pyhtml_htmx-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ecf1035eb942d0881f5a01f0d099cb3cacfd2dd57cb360559d7490751d8246a4
|
|
BLAKE2b-256 checksum How to use checksums |
7e0701a402693dc3d43015521d674e850863f47de0b228c72c81527932091a6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|