Live data from Hacker News

Ludic: New framework for Python with seamless Htmx support

github.com

81–90 of 107 posts

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

#81
post #13

I wrote a library a little while ago which is intended to be the simplest possible expression of this idea: https://github.com/j4mie/hotmetal/ The core implementation is only 85 lines of Python, and has no imports at all, so works nicely on minimal/alternative Pythons like Micropython. I'm using it on a medium-sized side project and it's shockingly productive compared to string templates. I don't think anyone is usin…

Elm [1] is based on a similar idea. Build your app from pure functions that return HTML tags.

[1] https://elm-lang.org/

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

#82
post #78

Earlier quoted context omitted.

But `a` is included. You don't have to build a `Link` component. If you want to stylize your links in consistently across your page, you can build your own Link. The example does nothing other than renaming `href` to `to` and adding a style. How should the framework know which styles you want to apply to a link? I think the example explains the component-driven design of the library well.

How would you feel if the first example in, say, a ruby tutorial, was how to redefine the ‘+’ operator to use a different symbol? It’s somewhere between pointless and confusing to me, and isn’t illustrative of why one would want to use components, or what a competent even is .

Interestingly, the second example on the official Ruby "About" page is almost exactly that: it defines .plus to be an alias of .+, and demonstrates how it might be used.

https://www.ruby-lang.org/en/about/

As a web developer (and therefore, I imagine, part of the target demographic for this sort of tool), I personally find this component example very useful. Components are very powerful, but most existing Python templating languages make it difficult or overly verbose to use them to their full extent. This is a really good demonstration of how I can write simple presentational components and use them with server-rendered HTMX. That shows off one of the main things I would want to do with this sort of framework.

So from that perspective, this is very much the perfect sort of example.

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

#83
post #82
post #78

Earlier quoted context omitted.

How would you feel if the first example in, say, a ruby tutorial, was how to redefine the ‘+’ operator to use a different symbol? It’s somewhere between pointless and confusing to me, and isn’t illustrative of why one would want to use components, or what a competent even is .

Interestingly, the second example on the official Ruby "About" page is almost exactly that: it defines .plus to be an alias of .+, and demonstrates how it might be used. https://www.ruby-lang.org/en/about/ As a web developer (and therefore, I imagine, part of the target demographic for this sort of tool), I personally find this component example very useful. Components are very powerful, but most existing Python temp…

That's a totally different presentation though. The ludic home page never mentions that there is an existing function/data type! It just goes straight into the definition of Link without giving any context to someone who doesn't know what htmx is. There is nothing to tell a naive reader that this isn't how you'd do this in a production app.

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

#84

Earlier quoted context omitted.

Until you try it out and realize the benefits! - Type safe HTML: you get an exception instead of malformed HTML - Truly reusable components: any Python web framework, component packages are truly reusable in any other projects. I never seen this with template engines. - Huge productivity boost: not even close! No hunting for templates, no jumping between files, everything is in Python functions. - Composable elements…

Yes, I quite like the idea of being able to run pyflakes/flake8/black/pytest/mypy over my "html templates", and benefiting from all the power that entails.

Try ruff [0] and get rid of flake and black

[0]: https://github.com/astral-sh/ruff

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

#85
post #4

I don't know, every time I see people sneaking html into Python feels weird and wrong to me...

It feels weird at the beginning, but after a bit of practice I found it pretty nice to write HTML in Python. Here is an example of a HTML page layout written with the DOMinate [1] library for example, in a "JSX-like" way: https://github.com/olivierphi/zakuchess/blob/main/src/apps/w... It may hurt your eyes at first sight, for sure... But similarly to technologies like Tailwind CSS, it's mostly a matter of getting use…

Dominate is quite fast as well. I did a few tests vs jinja for my flask app and it beat the pants off it.

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

#86
post #83
post #82

Earlier quoted context omitted.

Interestingly, the second example on the official Ruby "About" page is almost exactly that: it defines .plus to be an alias of .+, and demonstrates how it might be used. https://www.ruby-lang.org/en/about/ As a web developer (and therefore, I imagine, part of the target demographic for this sort of tool), I personally find this component example very useful. Components are very powerful, but most existing Python temp…

That's a totally different presentation though. The ludic home page never mentions that there is an existing function/data type! It just goes straight into the definition of Link without giving any context to someone who doesn't know what htmx is. There is nothing to tell a naive reader that this isn't how you'd do this in a production app.

I see where you’re coming from. What you are describing is the exact feeling I’m getting whenever I’m reading the man pages of older R packages.

But this might also mean that one is not the target audience in this case…

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

#87

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 think those are all good points, but do cringe a little at the idea that "to add your own JavaScript you'll want React". Seems like a lot to bring in if you're really just wanting to add some JavaScript.

React can be added by rendering into a dom node that's not necessarily the root of your app.

Yes, it can be used to render the entire UI app with rich state management across all pages, routing, etc.

However it can just as simply be used to render 1 complex part of an app that has an isolated but possibly complex state. In this scenario I think sprinkling react is reasonable.

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

#88
post #84

Earlier quoted context omitted.

Yes, I quite like the idea of being able to run pyflakes/flake8/black/pytest/mypy over my "html templates", and benefiting from all the power that entails.

Try ruff [0] and get rid of flake and black [0]: https://github.com/astral-sh/ruff

I'm aware of it, but it obscures functionality for my previous statement.

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

#89
Nice! A bit verbose for my taste but writing for the web in python is a space where all innovation is welcome.

I personally like hyperdiv [1] approach (even if no use of Htmx) which is very intuitive for python code.

[1]: https://github.com/hyperdiv/hyperdiv

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

#90

Earlier quoted context omitted.

I think those are all good points, but do cringe a little at the idea that "to add your own JavaScript you'll want React". Seems like a lot to bring in if you're really just wanting to add some JavaScript.

React can be added by rendering into a dom node that's not necessarily the root of your app. Yes, it can be used to render the entire UI app with rich state management across all pages, routing, etc. However it can just as simply be used to render 1 complex part of an app that has an isolated but possibly complex state. In this scenario I think sprinkling react is reasonable.

I'm admittedly out of touch with current React best practices, but "sprinkling react" isn't a phrase I'd have expected to hear based on my last contact with it. Sprinkling JavaScript or Alpine.js or HTMX, yes. But React seems to come with baggage, no?
Post reply on HN