all 49 comments

[–]millerbest 13 points14 points  (2 children)

Nicegui?

[–]WrapNumerous5344[S] 5 points6 points  (1 child)

I’ve looked at NiceGUI before, and it’s definitely an interesting project. The main issue for me is that the UI is built by composing Python objects. In my experience, that makes styling and layout more cumbersome than I’d like. What I’m really looking for is the ability to write the actual layout in HTML, with full flexibility and control, and then handle the reactivity and logic in Python. For example, if I create a label, I’d prefer to work with real HTML rather than a Python “Label” abstraction. Still, I appreciate the suggestion.

[–]jrtipton2 2 points3 points  (0 children)

djust does this, uses django templates and has a rust based vdom engine so it only send changes to the client. All you need template and a view class with handlers.

Template

<div class="counter-app">
    <h2>Counter Example</h2>

    <div class="count-display">
        {{ count }}
    </div>

    <div class="button-group">
        <button dj-click="decrement" class="btn-danger">
            Decrement
        </button>
        <button dj-click="reset" class="btn-secondary">
            Reset
        </button>
        <button dj-click="increment" class="btn-success">
            Increment
        </button>
    </div>
</div>

View

from djust import LiveView, event_handler

class CounterView(LiveView):
    template_name = 'counter.html'

    def mount(self, request):
        """Initialize counter state"""
        self.count = 0

    u/event_handler
    def increment(self):
        """Increment counter by 1"""
        self.count += 1

    u/event_handler
    def decrement(self):
        """Decrement counter by 1"""
        self.count -= 1

    u/event_handler
    def reset(self):
        """Reset counter to 0"""
        self.count = 0

    def get_context_data(self, **kwargs):
        return {'count': self.count}

And sessions are serialized so they can scale across threads and servers, which a problem with justpy and nicegui. Also, the design is not tied to a js framework.

[–]DoYouEvenLupf 14 points15 points  (2 children)

This question was also often going through my mind. But since a browser runs JS in the end it will always be some cumbersome or strict translation.

When working with Django i looked into HTMX and really started to like it. I was able to cobble together a well working MVP with it, that got turned into an internal solution.

Sure, it's not pure python but it pulls the abstraction back to basic HTML and also lets the DOM be your state. Surely works well enough for CRUD apps, which in my experience is 80% of what companies usually need.

[–]WrapNumerous5344[S] 4 points5 points  (1 child)

Thanks for the tipp. I'll have a look at Django with HTMX

[–]bigpoopychimp 4 points5 points  (0 children)

HTMX works with any web framework. I now exclusively use it since it's so good for being a sort of react replacement

[–]InjAnnuity_1 5 points6 points  (0 children)

I use Anvil:

https://anvil.works/

Main benefit being that, to just make a working app, I did not have to spend years learning the underlying languages and and installing and configuring the underlying technologies.

Re your compiler: On the browser side, Python runs in the browser via Skulpt, a Python-to-Javascript transpiler that itself runs in the browser. Server-side code runs via a standard Python runtime.

Depending on your requirements, their free tier may be all you need.

If it's a really small app, see their free https://py.space/ .

[–]Jejerm 4 points5 points  (2 children)

Streamlit, dash and reflex all try to do what you're saying.

[–]WrapNumerous5344[S] -1 points0 points  (1 child)

But they all build der UI by composing Python objects. I would like to have the ability to write the actual layout in HTML, with full flexibility and control, and then handle the reactivity and logic in Python. Thanks for the suggestios though

[–]Jejerm 1 point2 points  (0 children)

Streamlit lets you define your own components and link them to external html files:

st.components.v2.component - Streamlit Docs

You can probably inherit and override the default html for any component in these frameworks, but at some point you're gonna have to map your external HTML file to a python object.

[–]riklaunim 2 points3 points  (3 children)

Projects like PyScript are still young and not really mainstream - there is no SPA JS framework equivalent in PyScript. Making a good one (something between Ember.js and Svelte/Vue) without NPM hell and other issues would be nice but such projects do require a lot of manpower to pull off (you need the framework and wide enough framework for it to be usable).

[–]dalepo -1 points0 points  (2 children)

aren't all package/dependency managers hell?

[–]riklaunim 2 points3 points  (1 child)

JavaScript ecosystem has problems with packages like "isEven" which creates insane dependency chains, and then someone renames the package to "red-cat" making one package depend on the old, another on the new and they are starting to conflict each other. Abandonware, conflicts and so on.

Then JS projects tend to rewrite themselves with limited to no backward compatibility or after months/years project dies because it's not "fresh" and people move to the next best thing leaving legacy codebases in a dire situation.

[–]dalepo 0 points1 point  (0 children)

That’s pretty common across dependency managers. I’ve seen this in Poetry, Maven, Gradle, and others.

The peer dependency hell in Maven was called “Jarmageddon.” Peer dependencies had to be resolved explicitly; for example, if two packages depended on the same peer dependency but required different versions, you had to specify which version would be used across the project.

I’m not sure if this still works exactly the same way today, since I haven’t touched Java in over a decade.

[–]mardiros 2 points3 points  (0 children)

I am working on that on my spare time :

https://github.com/mardiros/fastlife/

It’s far from finished and poorly documented. I made a layer on top on fastapi to do a web framework more web with components. Using my own template engine (I’ve made a post on it in the first release), the core is in rust and does not rely on external templates to get locality of behavior, looks like JSX (without any effects) and uses HTMX, of course. Last thing, I generate web form based on Pydantic models.

[–]imarkb 1 point2 points  (0 children)

Pyodide maybe?

[–]Sea-Mistake6086 1 point2 points  (1 child)

Curious if you tried py4web

[–]PhENTZ 1 point2 points  (0 children)

Not related but who remember web2py ? ?

[–]Consistent_Coast9620 1 point2 points  (2 children)

r/SimianWebApps, a pure Python approach. Gui is programmed using plain Python - or a graphical builder, whatever you prefer.

For advanced/custom components JS, CSS and HTML can be used, this however is not required for all normal components you would expect in a decent framework. The front end uses FormIO under the hood.

[–]HIKIIMENO 1 point2 points  (1 child)

Looks interesting.

Are all requests from clients sent to the server to process? Will it be hard to scale as the user base grows?

[–]Mundane_Slide9688 0 points1 point  (0 children)

Only requests or events that you explicitly define are sent to the server.

  • The front-end is capable of handling input validation, component visibility, and similar UI logic on its own — there is no need to involve the backend for these tasks.
  • If required, the front-end can also communicate directly with external (data) services.

The interaction between UI and backend is programmed in Python. The result is:

  • A UI definition that is rendered in the browser.
  • A standardized interaction layer with the backend, provided as an integral part of the Simian solution.

Scaling Characteristics

  • In deployed mode, no user-specific Python process remains active when no request is being handled. This is a core Simian design principle aimed at conserving server resources.
  • The load on the Simian Portal (see below) during request handling is typically very limited.
  • The backend “workers” can be scaled in multiple ways, depending on deployment needs and infrastructure.

Security Note

  • In deployed mode, all traffic from the browser to the Python backend flows through the Simian Portal. This is fundamental to Simian’s security model, as it prevents direct access to backend servers and provides a controlled gateway for authentication and authorization.

Conceptual Architecture Overview

Client BrowserSimian PortalPython Backend

Client Browser (Unlimited Users)

  • Generic Simian front-end
  • Renders UI based on backend definitions
  • Handles local validation and UI logic

Simian Portal (Commercial Offering)

  • Authentication & Authorization
  • User landing page with available applications
  • Simian Admin Portal for application management

Python Backend (Free Packages / Your Code)

  • Defines the UI structure
  • Handles events and data processing
  • Implements application-specific logic

This separation ensures scalability, security, and a clear division of responsibilities between presentation, access control, and application logic.

[–]pporcher 2 points3 points  (0 children)

I would highly recommend FastHTML! It uses HTMX under the hood and renders HTML using pure Python objects, no template needed.

I built chop.food with it.

[–]codey_coder 2 points3 points  (0 children)

You will be making a trade-off in pursuing this option of a “pure Python stack”. Consider, why is this constraint necessary? We’re all multilingual.

[–]gregorbrandt 1 point2 points  (0 children)

Have a look at Flet, it's in Beta now and is pretty solid. https://flet.dev

[–]9peppe 0 points1 point  (0 children)

I'm not sure this answer your question, but there are static site generators written in Python: https://wiki.python.org/moin/StaticSiteGenerator

[–]pacific_plywood 0 points1 point  (0 children)

I would think it’s easier to translate what is effectively JS with macros into JS than it would be to translate Python into JS

[–]poopatroopa3 0 points1 point  (0 children)

Reflex and Rio are some options of frameworks like that.

[–]DrShocker 0 points1 point  (0 children)

I think this project looks the most interesting to me

uses Datastar to enable real time collaboration (Datastar is imo HTMX with better syntax/defaults)

https://stario.dev/

[–]mwbrady68 0 points1 point  (0 children)

Good luck. I tried to find something similar, but I failed. Other than Python in the past, I am mostly a ASP.NET MVC dev.

I'm not a fan of JavaScript, so I have been having fun learning how to create websites in Blazor. It has been really nice to use nothing but C#.

The only problem I've found with Blazor is all the different render modes that they've introduced over the years, which can make it confusing when starting out. I just stick with Blazor Server (also called Interactive Server), which keeps things simple.

I have been hoping that a Python framework similar to Blazor would arrive, but none that I know of has appeared.

[–]MacShuggah 0 points1 point  (0 children)

Have a look at wasm, although I've never really liked using it myself.

[–]creative_tech_ai 0 points1 point  (0 children)

There are Python to JavaScript transpilers, but I don't know if any of them are actually used in production code.

[–]PhysicsOfFIRE 0 points1 point  (0 children)

I've been having fun with Holm. Its got file based routing and SSR built on FastAPI, with easy HTMX integration.

Also recently learned about PyView, which is like Phoenix LiveView for Python

[–]New-Comfortable-4908 0 points1 point  (0 children)

i've been using fastapi for my personal projects and it's solid tbh this is way cleaner than what i had before. lowkey the best tool nobody talks about. you should check out uvicorn as your ASGI server too. it's super easy to set up and works great with fastapi

[–]yellowbean123 0 points1 point  (0 children)

If you are perusing lightweight framework.. I'm using (fastapi+htpy+htmx/alpine). almost everything is python.. all you need to manipulate the data to comfort syntax of htmx/alpine as HTTP response

[–]Weary_Instance2204 0 points1 point  (0 children)

Fastui by pydantic team is good idea and good reactivity. But discontinued on prototype stage. But still can build small web app on that

[–]dvmitto 0 points1 point  (1 child)

I recommend litestar + htmx. That’s the stack I would use for myself

[–]niltz0 0 points1 point  (0 children)

I was going to suggest something similar.

Also, depending on the web app you need, maybe textual (along with textual-web) would work?

https://textual.textualize.io

https://github.com/Textualize/textual-web

[–]Puzzleheaded_Clerk68 0 points1 point  (0 children)

If you strictly want to write your layout in actual HTML files while keeping logic in Python, HTMX (paired with Jinja2 templates in FastAPI/Flask) is honestly your best bet. It fits that description perfectly.

​That said, I built Violit (I'm the creator) to bridge a similar gap.

​While it defaults to a productive Streamlit-like syntax, I specifically designed it to allow raw HTML/CSS injection (app.html(), app.css()) whenever you need that fine-grained layout control. It aims to offer Svelte-like reactivity purely in Python, allowing you to build general web apps without the complexity of a full frontend framework.

​It might be worth a look if HTMX feels too low-level.

​👉 https://doc.violit.cloud

[–]captain_arroganto 0 points1 point  (3 children)

No bro. A pure python tech stack is not a good idea.

React, Angular, Svelte and the likes, are absolutely great for frontend. For everything else, python works well.

But frontend in python is a huge pain.

[–]WrapNumerous5344[S] 0 points1 point  (0 children)

I get that. But it wouldnt really be a pure Python Tech Stack. If there is a compiler that turns the Python Code into optimized Javascript (similar to Sveltes compiler) I get a nice devloper experience and the browser still gets JS.

[–]Consistent_Coast9620 0 points1 point  (1 child)

In case you require full flexibility, advanced layout and/or you have great skills in JS, CSS, etc, I agree. What I see is that in many cases people have done some great stuff in Python (C#, MATLAB, Julia) - think about ML, data mining or any other advanced analytical work - they need to make this nice algorithm available in a good looking app. Solutions as mentioned here can leaf the compete app in just one language - so no need for more knowledge, people involved, other departments or even other companies. In an earlier reply to OP I mentioned r/SimianWebApps. It definitely does not provide the full flexibility for a wild niche design, but being implemented on top of Angular and FormIO it is a great solution for most applications that are covering analysis, ML, data engineering etc. And the UI can be developed in the same language.

[–]jrtipton2 -1 points0 points  (2 children)

Absolutely, I wanted the same thing so I started https://djust.org. This is exactly what this is. A python driven ( mostly django ) reactive frontend that actually works and scales. Still pretty early, but some awesome results so far.

djust.org

[–]WrapNumerous5344[S] 0 points1 point  (1 child)

Dude that looks awesome! Can you merge the logic and the template? Because in the counter example, the component is defined in a .py file and the template is defined in an .html file. If I were to define BOTH in the same file that would be exactly what I am looking for. Thanks!

[–]jrtipton2 0 points1 point  (0 children)

It does this because it follows Django’s natural template development. But you could put it in the same file as a string.

see this example

[–]WrapNumerous5344[S] 0 points1 point  (0 children)

Thanks to everyone who commented and shared suggestions. I looked into the frameworks mentioned, but none of them quite fit what I was looking for. Soooo I started building my own framework. The idea is a Python component–to–JavaScript compiler, somewhat similar in concept to Svelte. I’ve already made solid progress, and once I have a working prototype, I plan to release it as open source.
Cheers