Hacker News new | ask | show | jobs
by 79a6ed87 1463 days ago
I would love to see Python in browsers more than Javascript. But since this works through WASM, I'd probably stick with Rust in that case.

If I'm going to be bound by the limitations of how immature WebAssembly is right now, I'd at least use its more mature ecosystem for development, which is Rust. And actually, I recently began doing so in my free time with a framework named Yew[1].

I know that it's unrealistic to expect Python to be a first-class citizen in browsers as JS is, but at some point we'll grow tired of reading "X language is now available for browsers" when it's more like "X can do WASM now".

edit: Anyway, I don't want to come off as under-appreciative of PyScript. I'm sure a lot of people will love it and make it grow a lot. I'd probably give it a try someday too. Props to the developers!

1 : https://github.com/yewstack/yew

2 comments

To me, the groundbreaking thing about this is the idea of embedding Python in its own custom script tag instead of compiling it to WASM. Maybe other languages have done that before, but I haven't seen it.

That you have to ship the entire interpreter isn't great, but what it means for development is that there is no compilation step. You don't have to deal with the WASM toolchain directly. You write your Python code, refresh the tab, and see the results. That's a huge step up from trying to use Rust and WASM for the majority of people who aren't yet Rust developers.

Obviously it's super immature at this stage, but the future possibilities are exciting.

Doing it inside <script type="text/python">…</script>, and having the library scan for such elements, has been a standard technique in such situations for over two decades (and for stylesheet languages, like <style type="text/less">…</style>).

Doing it inside a custom element like <py-script>…</py-script> has been done occasionally, but doesn’t work well because (a) the code is now visible in the document by default and only hidden by stylesheets, and (b) < and & now need to be escaped as &lt; and &amp;.

Great for Python developers, not so great for everyone else.

This is something I find common in the Python ecosystem. There seem to be a lot of choices made more for the benefit of the developers than the end users. Even getting a Python app with some idiosyncratic build system to run can be a challenge sometimes.

If you have to use a build system, you're not a user.
I have a vague recollection of Microsoft and/or ActiveState enabling Perl as a browser language. For a time there was an ActiveX interface for a bunch of script languages like Perl and Tcl.
It’s a great feature. Funnily enough this was a feature of the Grail web browser which actually came out a few months before the first version of Netscape with JavaScript (livescript) support
Damn, that's really cool. Too bad hype won out in the end...
Other languages have done that :)

Lua in the browser: https://fengari.io/

And then you can use that to run Fennel, a Lisp that compiles to Lua https://fennel-lang.org/

I think TypeScript also has a script you can include that lets you put your TS code in a special script tag, and it gets compiled in-browser.

Eeem... i have used Brython, maybe you will like it just as much as I do, i am not that sure how is it in performance yet to do minimal updates on text fields, handling butons and the like (as 99% of the web) it does just fine, you can even have animations. Finally front end code looks "clean" instead of looking like a project for computer science 101 as ... well 99% of the web hahaha

https://www.brython.info/

I tried brython but it fell at the first hurdle (I can't remember if it was xpath searches on the DOM or some XML manipulation in python), so I gave up. I'm sure it's better now, but the whole concept of binding Python abstractions to JS objects underneath felt a but clunky and it leaked a lot. WASM is definitely cleaner, if obviously slower.
Speaking of front-end, I really like Brython's site showcasing what they're doing. Just right-click > view source and you can immediately figure it out. On PyScript's site they use JS for the typing animation rather the framework they're making.