Live data from Hacker News

Ludic: New framework for Python with seamless Htmx support

github.com

101–107 of 107 posts

Re: Ludic: New framework for Python with seamless Htmx support

#101
post #79

This looks great! Building HTML on the server with static types and htmx is a very productive combination! At work, we have been exploring alternatives to templates in our Django project and just released it as a lib to help with this: https://htpy.dev/

Whoa, a creative (in a good way IMO) use of __ getitem__() dunder method to depict attributes and children. No action at a distance using with blocks, static and strongly typing instead of stringly typing, no need to extend Python, composable from fragments. Have you tried to "bring up front" if and for? For example > if_(cond, tag1(), tag2()) # without eagerly execute both branches Instead of > tag1() if cond else t…

Python's inline if's still read backwards to me and it would be nice to switch the order. But we are kind of stuck with it. I also don't want to introduce new control structures in this lib. Just want to use whatever Python has to offer in terms of control structures/syntax to make it more approachable.

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:

  True!
  False!
  abc

Re: Ludic: New framework for Python with seamless Htmx support

#102
post #99

I've been diving into Python/FastAPI + HTMX development and while I love both separately, I felt like the combined tooling could be a lot better. Jinja2 doesn't really satisfy me. At least not in this tech stack. I'm still a bit sceptical if this is the solution but I'm definitely going to look into it as it fixes a few things I'm annoyed with. Thanks!

Agreed. As someone who primarily develops in python, I recently tried this exact same stack as a way of avoiding the inevitable (i.e. learning typescript). After dealing with the complexity of interleaving templates, overly complex information flows, etc. I copied some of the html from the jinja templates I created into a svelte project, added openapi-typescript to glue it all together, and moved on. While I am by no means a fan of typescript and modern web development, it is much easier build things given the extensive ecosystem. And if nothing else, the “frontend” is separate all of the core logic, which makes things easier to understand.

Re: Ludic: New framework for Python with seamless Htmx support

#103

Nice release! This looks good, docs look really nice too. I'd use HTMX anywhere I can to improve a basic HTML site. One word of warning for people considering HTMX though – it's not a framework, it's an appliance. In my experience with it, I ran into problems integrating with HTMX very quickly. Drop it into your project, use the HTML attributes, and it'll be great. However if you need custom Javascript, HTMX provides…

I've actually found HTMX to work really well with custom elements for basic interactivity.

If most of your logic is server-side and client JS is kept small, custom elements let you lean on lifecycle events built right into the browser specs.

Re: Ludic: New framework for Python with seamless Htmx support

#104

Earlier quoted context omitted.

Is there any chance you are considering moving towards structured data as HTML, as in SXML, instead of putting things into fstrings?

Well, I would like it if the solution supported standard Python typing. Here I can create a "component" that expects a specific type of the first child and a specific type of the second child. I would probably have to use a separate tool for some kind of type-checking the SXML or something. BTW in Rust, you can create macros, that is something I like a lot as you can see in yew framework - https://yew.rs/docs/getting…

Whether compile time guarantees or not, even having HTML elements as objects would be better than putting them into the f-strings. With objects we could probably pattern match on then and traverse the tree, instead of having to rely on other tooling or even regex to search for things inside an f-string.

Re: Ludic: New framework for Python with seamless Htmx support

#105
post #14

I encourage anyone looking to do htmx to consider Kotlin and it's excelent kotlinx-html DSL. Lets you do stuff like this: https://github.com/corlaez/kotlin-htmx/blob/master/src/main/... Disclaimer: Not my code, just an example I found.

https://youryoure.com/?its

Re: Ludic: New framework for Python with seamless Htmx support

#106
post #49

Earlier quoted context omitted.

We've come full circle on naming HTML tools! https://en.wikipedia.org/wiki/HoTMetaL

Glad someone got the reference!

I'm glad it was intentional. :-) I don't feel as old. Still old. But less so.

Re: Ludic: New framework for Python with seamless Htmx support

#107
post #63

Earlier quoted context omitted.

Airium is close: https://gitlab.com/kamichal/airium

The problem with this is that it doesn’t map nicely to HTML (or more generally XML) as do s-expressions.

My https://pypi.org/project/xml-from-seq/ is a simple mapper from e.g.

    ['p', 'This is a ', ['a', {'href': 'https://example.com'}, 'link']]
to

    

This is a link

Post reply on HN