thomasborgen / hypermedia

Composable HTML rendering in pure python with FastAPI and HTMX in mind
MIT License
12 stars 0 forks source link

Hypermedia comparison to others #25

Open legout opened 1 month ago

legout commented 1 month ago

Hi,

first of all: Thanks for this nice python library.

I wonder, how Hypermedia compares to other python libraries for html creation like

See here for a list of other python libraries: https://github.com/stars/legout/lists/py-html

thomasborgen commented 1 month ago

Thanks for having a look at Hypermedia and asking this question

I don't really have time to make an in-dept comparison right now, but it is coming: #15

What I can do now is at least write about what Hypermedia does :)

I think the best feature of Hypermedia is the slot system. Bases can be defined, and Elements can have named slots that can be referenced for expansion through the .extend(slot, Element) method. This makes is quite easy to section up your code and sew it together as needed. And is very useful for </>htmx developing which is what i made Hypermedia for.

Other than that, because with Jinja2 you leave python land and there is no way to reference your types in a jinja template, I looked for something else. I found a few interesting ones, but I didn't like the syntax.

With Hypermedia, I want it to feel as if you are writing html with python. What I mean with that is that all our html elements are Camel Cased. Why? Because they are classes, and thats how we write classes in python. At the same time I want it to feel as similar to html as possible so it should be very easy to pick up.

comparison:

Html(
    Head(...),
    Body(
        H1("My Text"),
        Div("some content"),
    )
)
<html>
    <head>...</head>
    <body>
        <h1>My text</h1>
        <div>some content</div>
    </body>
</html>

Lately I found Ludic which is amazing, and had I found it before starting on this, I might not have made Hypermedia at all. However, Ludic also does a lot more than just creating html. Hypermedia will focus on creating composable html while giving helper functions and decorators for popular frameworks like FastAPI or eventually Flask and Django that helps with creating </>Htmx webapps.

Hope this answers your question

BR