News for hackers. Stuff that matters.
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.