170 points · by mondrian · 2y ago · 83 comments
I'm releasing Hyperdiv (https://hyperdiv.io), a framework for rapidly developing reactive browser UIs in Python, with immediate-mode syntax and using Shoelace (https://shoelace.style) as its built-in component system.
This short coding video will give you a good idea of what it is: https://www.youtube.com/watch?v=4XJKfxaqvGE
I wrote a brief article about the motivation and approach: https://hyperdiv.io/intro.html
Hyperdiv doesn't aim to compete with serious full-stack frameworks. The core aim was to make it easy and fast to prototype apps and build UI-based tools. I was originally motivated by internal tools at work -- feeling the need to quickly put together UI-based tools to share with both technical and non-technical coworkers, without having to stand up and maintain a full internal stack.
This is my first major open source release. I really appreciate your feedback and support. - Marius
The proof is in the pudding but its safe to say I'm ALL THE WAY interested right now.
Have you tried training an AI chatbot to write Hyperdiv apps? It seems like a good idea, and I'm just wondering whether you've tried it and what the results have been like. I might try it myself.
It's so funny how subjective that is — I liked the audio enough to tell the author about it in a DM. Then I come to HN and read that someone disagrees. :)
In general I get the impression that this approach, of teaching an LLM a small self-contained API like Hyperdiv's, can work better/less hallucinatory compared to trying to build apps with very large APIs like the DOM API.
I'd like to read the docs myself to find out, but it seems like they are not hosted on the website. I can see that I can install the package and run the docs command, but I'd really rather use the web browser I'm already in to explore a new (to me) project's docs.
You can also pass in a custom executor and use processes instead of threads.
Thanks for the feedback wrt docs app.
Just today, I started exploring the current web development ecosystem in Python. As a long-time Python developer, it is amazing to see all the recent work that has gone into making the web accessible to more than just JavaScript developers.
Despite seeing all these amazing new approaches (e.g., Reflex, Streamlit, and now this), I can't help but think there is still a need to rely on "more mature tech" (though this gap is closing) to make non-trivial websites in Python (and in general). After surveying the Python (and JavaScript) ecosystem, I personally decided that a simple stack consisting of FastAPI, Pydantic, SQLAlchemy, Jinja2, Tailwind CSS, and HTMX would be the fastest approach to build a non-trivial app using Python.
With that being said, I will definitely circle back around in a month or so to see how things have progressed. I wish you all the best in making Python a contender for the next generation of web development.
SQLite, Linux, Apache/Nginx, PHP
It’s reminiscent of LAMP, so it’s very easy and cheap to deploy and maintain. I do wish the P stood for python instead of php, but Nginx integrates so well with php and doesn’t require a long running process like PM2 (nodejs) or Gunicorn.
Question: does this mean the server is stateful? Or is the state send with every request?
Hyperdiv does this:
def my_ui(hide_text=False): button("Button 1") if show_text: text("Hello") button("Button 2")
Hyperdiv is a generic framework with unrestricted layouts (but you can use a template if you want), and a component architecture where all components, whether UI components or internal state, are fundamentally similar and expose stateful props.
By contrast, Hyperdiv lays out UI declaratively based on state, and when state changes, the app re-runs, generating an updated UI. Streamlit and Hyperdiv seem to work similarly, though I'm not sure how Streamlit handles state and state-based layout.
We already support frameworks like Streamlit, Gradio, Shiny, Solara, Voila, among others. Ping me if you're interested!
Makes me realize how webdev is still just teeming with stupid levels of incidental complexity, and I'm not sure I trust webdevs to actually get us out of the tarpit.
I happen to be working on a standardized protocol (braid-http) for sending diffs over HTTP, and have been thinking about applying it to hyperdiv. I'd love to understand your use-case and what about plain HTML you like here.
Answering your question: it’s mostly the curmudgeonly tendency to avoid custom protocols that are harder to introspect and debug. It’s possible that the hyperdiv sync protocol is super intuitive and simple, but whenever possible I’d like to use boring web standards to reduce the surface area that I’ll feel the need to learn.
It also allows standard tools and front-ends to work with any back-end. We could have CDNs that can cache and sync dynamic HTML for a set of users without touching the server.
The dom sent over the wire is very similar to html but it’s json.
Then the diff is a json that indicates whether to add children and at which index, whether to remove children and at which index and how many, and attributes to update. This is the part I’m unsure of there being an analogue in protocols like htmx.
Easiest way to see it in action currently is to run a Hyperdiv app, open chrome dev tools and watch the websocket traffic on /ws
https://news.ycombinator.com/item?id=39353269
example app: https://github.com/thejchap/pue/blob/main/example.py
good luck! i think there’s definitely something here with this kind of thing
I'm curious, why you went with Shoelace? Was there anything else you considered instead? Doing things at the right level is tricky. I'm just curious how you arrived at the level you've got with Shoelace in Hyperdiv, over others. Nice work!
At one point Hyperdiv’s frontend was using Svelte and Svelte Material UI components. I explored other options before settling on shoelace.
Shoelace stuck primarily because it’s very solid and uniform. Ran into very few issues attempting to integrate it. And it being web components allows for a clean and straightforward vanilla JS frontend without dependencies on frontend frameworks. (I love Svelte a lot, but the Hyperdiv Svelte frontend was pretty gnarly.)
Re: Async - there could potentially be speed benefits and simplifications if async interfaces were exposed instead of synchronous functions, right? Maybe it's not more simple, maybe async is a trap for the use cases you see that would overcomplicate (totally possible)? Being able to do stuff like await multiple API requests to LLM's and deal with the first to return, or wait for both, is the kinda thing that Python's async interfaces can make easier and I notice that you're already using Tornado for websockets under the hood, which is natively async I think, but the Hyperdiv examples I saw weren't using async functions so I wondered about what the side effects of that could be. Maybe you already have exposed interfaces for it and I've just overlooked them? Edit: I just noticed you said you have async function support! Well, I wonder how deep it goes? I guess you know when something breaks? Anyway really nice presentation of the problem and solution, nice work!
Re: nicegui, I like nicegui. Hyperdiv and nicegui are similar in that they're "build web UIs in Python" frameworks but take significantly different approaches. See this comment: https://news.ycombinator.com/item?id=39458641
Re: async. Hyperdiv's main function, which generates the UI, runs synchronously, indeed. But the main function can spawn off asynchronous calls. For example:
async def api_call():
data = await get_data()
return data
def main():
task = hd.task()
task.run(api_call)
if not task.done:
hd.spinner()
else:
hd.text("Loaded data:", task.result)
This app spins off an async call to api_call(). While the call is running in the background, a loading spinner is displayed. When the task finishes, its return value is rendered.Async tasks can also update state gradually while they run:
async def api_calls(state):
data1 = await get_data1()
state.data1 = data1
data2 = await get_data2()
state.data2 = data2
def main():
state = hd.state(data1=None, data2=None)
task = hd.task()
task.run(api_calls, state)
hd.text("Data1:", state.data1)
hd.text("Data2:", state.data2)
This app will initially display "Data1: None\nData2: None". When get_data1() finishes running, the UI updates to show the result for "Data1", but the result for "Data2" is still None. When `get_data2()` finishes running, both fields are then filled.You can also write an async function that runs indefinitely, continually listening on some I/O channel and updating state as new data arrives. When the app exits, it can signal the task to exit.
This scratches a good itch that Streamlit just seems to baaaaaaaaaaaarely miss -- more fine-grained control of the React under the hood.
Keep it up!
One key feature of BEAM, has always been its ability to sustain high user count with this architecture, as its totally ok to have “a thread per user” on your server.
Wondering now how hyperdiv scales to thousands/millions of users, given python’s inherently stateful nature, what’s the key tech that made it possible?
Separately, all of the above seem to lack official auth solutions. People with experience in all of these, do you just roll your own or integrate with something else?
By contrast, Hyperdiv runs everything in Python and ships DOM and DOM patches to the browser.
Anyway, I tried to look around and it seem to be lacked any component to upload files. Is it in the pipeline or I missed something?
I hadn't heard of shoelace before, but I love how easily you split things out into named components in the demo. Really cool mix of tech
Hyperdiv expresses UI declaratively based on state. As state changes, the app re-runs, producing a changed UI.
I fully agree that it is a great project and that there is plenty of space to have different frameworks with their specialties that allow to choose the best one based on the circumstances.
> htmx being involved
I think it's possible. Hyperdiv uses a custom DOM patching system but I could imagine it being swapped for an existing HTML over the wire tech.