Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I started learning FastHTML but somebody on reddit mentioned htpy. In my opinion htpy+fastapi is awesome combo. I like the way htpy handles declaring html components.

http://htpy.dev



I don't quite get an abstraction like this, if in the end both in our minds and through [trans|com]piler it's necessary to know the underlying abstraction in details(?)


The benefit comes as you're generating chunks in python, then you're passing around python objects rather than strings, string templates, etc.

It's also a bit of an odd thing to be in python, then just because you need to loop you need to write Jinja or other templates which are different languages basically. Might be nicer to write a loop in python.


Why would you use fastapi if you're rendering with htpy, instead of just using Starlette?


I've used FastAPI, but haven't done a lot with Starlette directly. If you are building a full stack app, I can imagine the integration between FastAPI and Pydantic can make it easier to work with the data that you might want to render in the HTML that you generate using htpy?


htpy is just server-side rendering of HTML. Your routes are returning strings instead of structured data, so from the perspective of responses you're not going to be using Pydantic at all. That doesn't stop you from using it to validate objects you're passing around in your server, but I personally wouldn't do that because Pydantic can have a pretty hefty memory footprint. I've seen over-reliance on pydantic lead to plenty of OOMKilled errors.

It's a bit different for requests though. FastAPI will allow you to define your request schema (application/json or application/x-www-form-urlencoded) and validate it using pydantic, but starlette doesn't do that OOtB. It's trivial to implement though, and if it were me I would probably choose to do that rather than deal with FastAPI's inflexibility.


I would like to know this also.


Always wondered why there doesn’t exist a pyx like there exist a jsx/tsx. Is it just not feasible


I have a feeling the Python Template Industrial Complex; which includes Jinja, tag(anothertag("text")) DSLs, GVR's pyxl3, Kivy UI language; will all go away if Python has something as convenient as JSX.


Something similar already exists:

https://github.com/pyxl4/pyxl4?tab=readme-ov-file#inline-pyt...

It's a shitty experience.


Thank you for the link!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: