Live data from Hacker News

Ludic: New framework for Python with seamless Htmx support

github.com

51–60 of 107 posts

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

#51
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…

This looks like a similar model to how Elm handles HTML. Except Elm provides functions for each tag, so it also does type checking to ensure that the passed arguments correspond to the actual attributes of the tag.

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

#52
post #17
post #9

Earlier quoted context omitted.

How have you been burned? What kind of bugs did you have, and in what way was it difficult to debug?

Here's a bug I ran into with Python async: https://stackoverflow.com/q/78036302/265521 I've written about 200 lines of Python async code in total, so to run into a bug like that so soon was not encouraging. I suspect it's just not a very popular feature and so it doesn't get a lot of use and debugging. And it's Python so it really needs a lot of ton of real world use to detect bugs. Anyway I'm not going to waste my t…

Haha someone didn't like that I'm pointing out flaws in Python and down-voted that question.

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

#53

Earlier quoted context omitted.

Myself I built an RSS reader using aiohttp and then forked the code to make an image sorter. I had a lot of people tell me I was crazy to write aiohttp servers because of the problems the previous poster mentioned but I had a long run of it working pretty well. On the other hand I’ve frequently had the experience of writing something in Python that falls apart like a tower of Jenga blocks the moment somebody else tou…

> Once I started serving images along with the text and using the app over a 2Mbps link it seemed to me the aiohttp server was getting a little unreliable. Does that imply that it was due to images being heavier, and thus if you were to stream something like video from aiohttp it would not go so well?

For video I think I'd use nginx or something like that. The aiohttp server is meant for serving dynamic content, nginx is using async io too but it is written in C and optimized in every way.

Currently for my case the worst problem is head-of-line blocking, the system could be downloading 50 large images but to put a tag on a gallery it needs to load a small HTML page for a modal dialog, then it has to populate a dropdown box after a tag category is selected, then process the form request.

Since all these images are queued to download, the system has trouble prioritizing the HTML requests. The best answer to this for me is to build that thumbnailer to get the image size down, but I am also thinking of putting images on an entirely different port.

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

#54
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…

Reminds me of dominate.

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

#55
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…

This is wonderful, I love it. I recently wrote a blog post about generating HTML in Python using LXML (https://ricardoanderegg.com/posts/python-build-html-componen...) and I didn't know about your library. I'll update it to add a mention to it.

Apart from the simplicity, I like the fact you can "install" it by copy-pasting the code at the top of your script, or running:

  curl -L https://raw.githubusercontent.com/j4mie/hotmetal/main/hotmetal/__init__.py >> myscript.py
which is nice when you want a self-contained file.

I think I'll be using this in the future.

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

#56
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 used to it - and after a while it end ups feeling very natural to use :-)

1: https://github.com/Knio/dominate#readme

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

#57

Generating `HTML` from lisps has poisoned any other approach for me, see for example https://www.neilvandyke.org/racket/html-writing/ , https://reagent-project.github.io/ , and https://edicl.github.io/cl-who/

That's very nice, I wonder if we can write a sort of dsl for this in python.

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

#58
post #3

Earlier quoted context omitted.

By React-like component approach, do you mean using functions instead of templating language?

I think it is somewhat similar to React, for example, you can create a Link component like you can see in the README.md Now you can use it in f-strings, and well, other components. The idea from the beginning was to integrate it with htmx.org, so to me, it feels kind of similar when you are writing endpoints using these "components". But I understand why you are raising this question, I also didn't know how to name i…

FWIW, my reaction to the Link example was pretty much "Why do I have to build this, why isn't such a basic thing that any project would want not batteries-included?". Not the greatest first impression.

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

#59
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…

Nice work! There are a few expressions of this idea. There's a reason people keep coming back to it: it's actually really nice to write markup this way.

https://github.com/weavejester/hiccup https://github.com/JuneKelly/sneeze

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

#60
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.

This is a lovely use of the DSL..too bad I prefer plain java.
Post reply on HN