Comment by davepeck

Comment by davepeck 3 days ago

9 replies

I'm excited to see more projects like Rio exploring the full-stack python web dev space. There are definitely categories of users for which the approach makes sense.

---

For me personally -- and I'm guessing for a bunch of other HNers -- writing full-stack web apps strictly in python is a non-goal.

I've settled on a comfortable (for me) stack for smaller projects that need python on the backend that combines:

1. Litestar (or another lightweight HTTP framework of choice like flask, etc.)

2. HTMX

3. htpy.dev (an in-python HTML builder)

4. Custom web components implemented in a plain-old JavaScript ES6 module loaded directly by the browser

A typical project only needs a handful of components. HTMX and htpy.dev both play very nicely with web components.

When I want zero build steps, I write plain JavaScript + JSDoc comments. JSDoc is... okay-ish, but it ain't no typescript.

If I need a database, I'll grab SQLAlchemy. I wish there were a mature lightweight solution here; maybe Tortoise ORM will get there soon?

There's nothing in this stack that couldn't strictly be done in javascript-land. JSX syntax with HTMX is pretty great and much better than any in-python HTML builder. But often my projects have other requirements (like ML) where python is, at least today, inevitable.

Sn3llius 3 days ago

Rio dev here. I 100% agree with you. We aren't expecting for JS developers to flock to rio en-masse. Instead, we're targeting the many, many Python devs that have been completely left out in the web revolution and are still stuck construcing user-interfaces using tkinter and similar.

synergy20 3 days ago

Hopefully JSX can be more mainstream, that is, I can use it directly in js/html/css projects without all the extra tools pre-installed and pre-configured, making jsx part of the 'vanilla' development will be really nice(no react, no vuejs etc).

  • timkq 2 days ago

    I agree about the JSX part - but the thing about real dev is that you have to use all the tools you can, so you don't have to reinvent the wheel. Nobody's still making Windows-only GUI apps using the Win32 API - it's easier and all, but there's so much stuff you have to code yourself that it's simpler to learn a GUI library/framework and Just Use That. I had a quick glance at HTMX - and it seems to just be going backwards (similar to Go - the language is so simple that it's actually hard to code real stuff in it). Why should I make an API that's essentially web only (because you have to send back HTML from the server using HTMX) if I can just use JSON/Protobuf/etc. and with just a few build tools I can automatically generate functions that I can call directly in JS. Sure, it's easier to build a website with plain JS (and by that HTMX, which is glorified plain JS) but this is the real world.

nomdep 3 days ago

> If I need a database, I'll grab SQLAlchemy. I wish there were a mature lightweight solution here; maybe Tortoise ORM will get there soon?

[Peewee ORM](https://docs.peewee-orm.com/)

  • davepeck 3 days ago

    Peewee never quite got there IMO, and it hasn't kept up with the times (modern asyncio, etc.)

    • nomdep 3 days ago

      Is there really an “etc”? Beyond asyncio, I haven’t found anything that SQLAlchemy can do that Peewee can’t even more easily.

mixmastamyk 3 days ago

Where’s a good place to learn about the web components aspect? I’ve tried a few times (and the shoelace docs) but it doesn’t stick.

  • davepeck 3 days ago

    I may be the wrong person to answer, alas. I nearly entirely avoid the machinery of web components.

    With the stack above, I typically write small classes that derive from HTMLElement and implement a couple key callbacks (usually, connectedCallback and disconnectedCallback). In those, I typically (a) initialize state by reading attributes from the DOM and (b) configure event handlers. Pretty simple.

    That's... about it. I'm templating elsewhere, so I avoid using web component templates. And the less I think about the shadow DOM, the better.

    For this, the MDN documentation on custom components is enough.