News for hackers. Stuff that matters.
Re:It's React, but in Python by ironmagma on Tuesday June 06, 2023 @10:16PM (#36222015)
I created something like this inside a tech giant once. It never saw the light of day with regard to usership. It's good to see someone doing the same in the open source world.

A brief summary of what I did:

* Python-powered apps, like this

* React was used to handle lifecycle. Basically, I avoided writing any kind of lifecycle management because I just wanted to do exactly what React would do. This was achieved via events firing when React lifecycle events fired. If props changed on the server, I'd send the new props to React to see if it would trigger a lifecycle event. If a lifecycle event was triggered, I'd replicate it onto the server which could again render new props.

* The result was a nice seamless support for both native React components and the newfangled Python components (which could be made up of either more React components or Python components).

* The purpose of all of this was to cater to ML engineers who didn't particularly like JavaScript and just wanted to build their analyses with Python and share them with coworkers. We had an automatic deployment system for them to share these.

* Only caveats were around session management. Much of the state was handled on the server via a websocket, so if your connection dropped, you lost all ability to update the layout. Load balancing was going to be tricky, since the sessions would have to be shared somehow. I was thinking about serializing and deserializing using Pickle but never really got around to deployment.

See also: [Dash](https://github.com/plotly/dash)

Re:It's React, but in Python by abhayhegde on Tuesday June 06, 2023 @10:36PM (#36222163)
Oh, I had a case where I had built an ML based recommendation app, and utilized Flask for serving the results on my localhost. Would have loved to use React but my lack of sufficient JavaScript knowledge prevented me from doing so. Your tool seemed to have perfectly catered to my needs!
Re:It's React, but in Python by ironmagma on Tuesday June 06, 2023 @11:17PM (#36222444)
Dash could probably get close enough as well. It's a bit limited compared to React but provides quite a lot of interactivity. (Plus, the server is stateless which is nice.)
Re:It's React, but in Python by abhayhegde on Wednesday June 07, 2023 @01:43AM (#36223291)
I'll have to give a try then!
Re:It's React, but in Python by KRAKRISMOTT on Wednesday June 07, 2023 @02:14AM (#36223460)
Re:It's React, but in Python by ironmagma on Wednesday June 07, 2023 @10:32AM (#36227261)
Cool idea but it wouldn’t have worked for what we were doing. The Python side definitely needed to be on the server because it was dealing with database connections, talking to other services, and doing heavy duty dataframe manipulation.
Re:It's React, but in Python by rmorshea on Wednesday June 07, 2023 @03:41PM (#36232389)
At some point we'd like to add client-side components to ReactPy. This might be an interesting avenue to explore in that regard.
Re:It's React, but in Python by devxpy on Wednesday June 07, 2023 @05:01AM (#36224529)
The way to solve session management is to just store the state in html forms and send it back to a stateless http endpoint. That way you get a website that behaves the way all websites work, and can scale easily.
Re:It's React, but in Python by ironmagma on Wednesday June 07, 2023 @09:33AM (#36226585)
The trouble is though that you also have state in Python which can’t necessarily be represented in Javascript, such as a database connection. You could pickle it, but accepting a user-provided pickled value is a security risk. Also, doing so would leak database credentials, and recreating the state on the server every event is expensive anyway. It’s better to just have one dedicated machine per application session that holds the state for the duration of the app.
Re:It's React, but in Python by rmorshea on Wednesday June 07, 2023 @03:37PM (#36232334)
ReactPy dev here. We haven't actually landed on how we want to solve this problem yet. We have some ideas though. Would be curious to hear your thoughts on this issue: https://github.com/reactive-python/reactpy/issues/828

We think option 4 looks the most appealing.

Re:It's React, but in Python by ironmagma on Thursday June 08, 2023 @09:02AM (#36241167)
Wish I could help, but I never got as far as auth, and it sounds like ReactPy takes a bit of a different direction anyway. Looking forward to digging in but just haven’t gotten to it yet. Thanks for surfacing though!
Re:It's React, but in Python by devxpy on Thursday June 08, 2023 @05:59AM (#36239424)
Don't use pickle. Use JSON for stuff you can't represent in HTML forms.

For database connections, large datasets, etc (stuff you can't send off to the browser) use redis.

This is a trade-off between DX and UX. Holding session state means you need sticky session routing, and restarting servers kills your user's sessions. Plus imposing a websocket on your users is a cardinal sin, makes scaling incredibly hard, makes page load times abysmal, makes disconnects a nightmare for both you and your user.

Its fine if you're creating something like stable diffusion web ui though, which is meant to be a single user app.

Re:It's React, but in Python by ironmagma on Thursday June 08, 2023 @08:41AM (#36240905)
I find these dogmas to be presumptuous. For the use case, Pickle would be fine. Scaling was essentially a non-concern… it was an internal tool behind a VPN and the usage was below a dozen (and at most would have grown to dozens).

JSON is an alright storage format but it can’t do infinity, nan, or many other values important to Python. Also, you would have to write a reifier and serializer for every value. These simply create a problem rather than solving one.