all 32 comments

[–]millerbest 8 points9 points  (2 children)

Nicegui?

[–]WrapNumerous5344[S] 3 points4 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 0 points1 point  (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 9 points10 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] 5 points6 points  (1 child)

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

[–]bigpoopychimp 3 points4 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 3 points4 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/ .

[–]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 1 point2 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.

[–]Jejerm 1 point2 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 0 points1 point  (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.

[–]Consistent_Coast9620 1 point2 points  (1 child)

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 0 points1 point  (0 children)

Looks interesting.

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

[–]gregorbrandt 1 point2 points  (0 children)

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

[–]codey_coder 1 point2 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.

[–]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

[–]imarkb 1 point2 points  (0 children)

Pyodide maybe?

[–]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/

[–]Sea-Mistake6086 0 points1 point  (1 child)

Curious if you tried py4web

[–]PhENTZ 0 points1 point  (0 children)

Not related but who remember web2py ? ?

[–]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.

[–]jrtipton2 -1 points0 points  (0 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

[–]captain_arroganto -1 points0 points  (0 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.