11 karma · joined Jul 24, 2012 (14y ago) · 12 submissions
comment 1mo ago · link · parent
comment 1y ago · link · parent
So to us, htpy performance has never been an issue which is why we have not been optimizing it further. If anyone is interested in re-implementing parts of htpy in cython/rust/something or improve the performance in other ways, that should be quite doable. The core htpy element/attribute implementation is a few hundred lines of code. It is heavily tested with 1000+ lines of tests. It could be a quite fun project, contributions are welcome!
comment 2y ago · link · parent
comment 2y ago · link · parent
I agree about that HTML looks better with tags and it takes a bit of getting used to the python syntax. If something like JSX was possible in Python with all the tooling working, that would be great.
comment 2y ago · link · parent
comment 2y ago · link · parent
The real benefit is using this bootstrap modal component within your app, since it is just a regular function call. You can leverage your editor "goto definition" and static type checking within all the functions make up your web sites/apps HTML.
10.
Show HN: Htpy – generate HTML from Python without templates(htpy.dev ↗)
7 points · by pelme · 2y ago · 2 comments
comment 2y ago · link · parent
htpy supports generators/callables as children (https://htpy.dev/streaming/). As long as you are careful to wrap things in generators/lambdas everything is lazy. Implementing if_ and for_ is straightforward and anyone can build constructs like that to use. But will not be lazy unless all arguments are wrapped in lambdas:
from htpy import div, li, ul
def if_(cond, a, b):
return a() if cond() else b()
def for_(items, func):
return (func(item) for item in items())
print(div[if_(lambda: True, lambda: "True!", lambda: "False!")])
print(div[if_(lambda: False, lambda: "True!", lambda: "False!")])
print(ul[for_(lambda: ["a", "b", "c"], lambda x: li[x])])
output: <div>True!</div>
<div>False!</div>
<ul><li>a</li><li>b</li><li>c</li></ul>