Show HN: Mesop – Open-source Python UI framework
130 points| willchen | 1 year ago |google.github.io | reply
A small team of us at Google have been developing Mesop as an unofficial 20% project for the past few months. A wide range of research and product teams at Google have been using it to rapidly build internal apps and we’ve gotten a lot of positive feedback internally so now we’re looking to get feedback from the open-source community.
We think that Mesop provides a unique approach to building web UIs in Python - making it both easy to get started and also flexible enough to build customized UIs for a wide range of use cases. You can learn more about why we built Mesop here: https://google.github.io/mesop/blog/2024/05/13/why-mesop/
To look at some example Mesop apps, check out our demo gallery: https://google.github.io/mesop/demo/. Also, the demo gallery itself is built with Mesop: https://github.com/google/mesop/blob/main/demo/main.py which demonstrates the type of flexibility you have in building apps with Mesop.
A couple of us will be on here answering questions. Let us know what you think!
[+] [-] herrington_d|1 year ago|reply
I appreciate OP's ideas about how this project is compared to Streamlit?
[+] [-] willchen|1 year ago|reply
Where I think Mesop shines is that you get a lot of flexibility, just by writing your UI in Python. For example, Mesop has an out-of-the-box [chat component](https://google.github.io/mesop/demo/), but if you need to customize it, you can actually just copy the [chat.py file](https://github.com/google/mesop/blob/main/mesop/labs/chat.py) and customize it however you want.
In comparison, Streamlit is great to get started with, but once you're trying to do some complex customizations, you'll often need to write your own React/TypeScript component.
I think the other thing is that Mesop has a [different philosophy for building UIs](https://google.github.io/mesop/blog/2024/05/13/why-mesop/) (e.g. based on functions) which results in a distinctly different developer experience. This is, of course, subjective, but I think the Mesop approach scales well as your app grows (e.g. thousands of lines), which even internal tools and demos oftentimes do.
[+] [-] solidasparagus|1 year ago|reply
But the demos aren't very pretty :(
I feel like being able to build something beautiful should be a requirement for any tool to build UIs. People like me who care about the looks aren't afraid to dig into CSS as long as you make it feasible (cough streamlit cough).
[+] [-] willchen|1 year ago|reply
[+] [-] jbednar|1 year ago|reply
[+] [-] willchen|1 year ago|reply
[+] [-] c4wrd|1 year ago|reply
The project highlights the utility of Bazel more than I have seen before. How long did it take you (and others) to become as fluent as you are in Bazel and working with it?
Additionally, you (Will) seem to have a very intuitive grasp of build processes in general, notably many of the scripts are fun to dive into and have a very clean design. How did you familiarize yourself so well with those sorts of concepts? Do you have any recommended readings or side-projects you’d recommend tackling to get experience with?
[+] [-] willchen|1 year ago|reply
What helped me the most was looking at other projects using Bazel with similar tech stacks and then assembling it together, e.g. :
- https://github.com/angular/components - https://github.com/tensorflow/tensorboard
Alex Eagle of https://www.aspect.build/ has a lot of great resources on using Bazel - both on YouTube and the aspect website.
[+] [-] groodt|1 year ago|reply
I'm surprised to see nobody has mentioned gradio yet. It seems to sit in the same niche as streamlit and mesop.
https://gradio.app/
[+] [-] gostsamo|1 year ago|reply
[+] [-] willchen|1 year ago|reply
[+] [-] d4rkp4ttern|1 year ago|reply
One of the key requirements in a multi-agent chat app is to be able to display steps of sub-tasks nested under parent tasks (to any level of nesting), with the option to fold/collapse sub-steps to only view the parent steps. I was able to get this to work with chainlit, though it was not easy, since their sub-step rendering mental model seemed more aligned to a certain other LLM framework with a partial name overlap with theirs.
That said, I am very curious if Mesop could be a viable alternative, for this type of nested chat implementation, especially if the overall layout can be much more flexible (which it seems like), and more production-ready.
[1] Chainlit https://github.com/Chainlit/chainlit
[2] Langroid: https://github.com/langroid/langroid
[3] Langroid ChainlitAgentCallback class: https://github.com/langroid/langroid/blob/main/langroid/agen...
[4] Langroid chainlit demos https://github.com/langroid/langroid/tree/main/examples/chai...
[+] [-] sergius|1 year ago|reply
How does it compare with https://flet.dev/ ?
Does it compete in the niche of making simple things easy and hard things possible?
[+] [-] abdullahkhalids|1 year ago|reply
[+] [-] willchen|1 year ago|reply
Re: flet - flet intentionally takes a more imperative approach whereas Mesop embraces a declarative UI approach (as popularized by React, et al). I think the declarative UI approach scales better as apps get more complex, but I think the best way to see the difference is to look at some of the examples and see which approach you like more.
Re: nicegui - at the high level, there's definitely some similarities with the component-centric UI model. The data binding/state management works quite a bit differently and Mesop's approach provides stronger type-safety and, IMO, is more Pythonic, but that said, there's a lot of good options in this space and I think it's neat to look at all the innovation that's happening here, and ultimately, some of this is based on aesthetics and how you like to code your UIs.
[+] [-] kennethwolters|1 year ago|reply
Looking through the docs I am guessing a nice place for auth to hook into is the on_load parameter of the pages API? https://google.github.io/mesop/api/page/#mesop.features.page...
[+] [-] jackson928|1 year ago|reply
[+] [-] EddieLomax|1 year ago|reply
[+] [-] willchen|1 year ago|reply
For example, the demo gallery (https://google.github.io/mesop/demo/) itself is a Mesop app which is hosted on Cloud Run
[+] [-] spankalee|1 year ago|reply
[+] [-] giancarlostoro|1 year ago|reply
[+] [-] willchen|1 year ago|reply
I think supporting Python -> WASM could be one of the options we support, but there's probably always a need to support Python on the server, simply due to the ecosystem (e.g. dependencies) that's around it.
[1] https://pyodide.org/en/stable/project/roadmap.html#reducing-...
[+] [-] appveyor|1 year ago|reply
[+] [-] devtom|1 year ago|reply
[+] [-] willchen|1 year ago|reply
Re: calling backend, yeah you can use requests or anything else (e.g API client libs, talk to DB directly). The beauty is that you're just writing regular python code
[+] [-] zinclozenge|1 year ago|reply
[+] [-] willchen|1 year ago|reply
Mesop also drew inspiration from frameworks like LiveView (for Elixir/Phoenix) https://hexdocs.pm/phoenix_live_view/welcome.html which have demonstrated the viability of building server-driven web UIs for a number of years now.
[+] [-] VagabundoP|1 year ago|reply
At the moment I use Flask/htmx/tailwind for my apps, but I like how succinct this framework is, but how themable is it?
[+] [-] willchen|1 year ago|reply
If you like tailwind, I think you will like this as it's essentially like writing inline styles, but with a Pythonic, strongly-typed API.
[+] [-] oars|1 year ago|reply
[+] [-] unknown|1 year ago|reply
[deleted]
[+] [-] FloatArtifact|1 year ago|reply
[+] [-] willchen|1 year ago|reply
I haven't used it personally (this is separate from mesop), but it looks like a way to program desktop guis (among other platforms ( in Python
[+] [-] FKFnwL|1 year ago|reply
[+] [-] zerr|1 year ago|reply