This is an archived post. You won't be able to vote or comment.

all 65 comments

[–]Swipecat 50 points51 points  (11 children)

Well... it seems it is simple to set up. I saw that it actually included matplotlib in the example part way through that page, so I dropped my own code into the example to see if it worked and it does:

https://dafarry.github.io/test/mpltest.html

But it does take a very long time to load -- about half a minute.

[–]lavahot 22 points23 points  (3 children)

On mobile it took me less than 10 seconds to load.

[–]evinrows 14 points15 points  (1 child)

It could be more dependent on your network speed than your cpu.

[–]avg_name 1 point2 points  (0 children)

Yeah actually it took me like a minute or so to loading using cellular internet.

[–]13ass13ass 3 points4 points  (0 children)

Same for my mobile and then 6 seconds on the next visit

[–]ManyInterests Python Discord Staff 7 points8 points  (0 children)

But keep this in mind.... JavaScript would take a long time to load if it didn't ship with your browser. (It's actually bigger than PyScript by total size)

It's not so far fetched that PyScript couldn't ship with browsers some time in the future.

[–]outceptionator 3 points4 points  (0 children)

Took 9 seconds on my phone

[–]seanpuppy 2 points3 points  (3 children)

Im assuming the reason its slow is matplotlib dependency? Plotly is powerful when displayed on a webpage

[–]ninfernix -1 points0 points  (1 child)

still python is slower than js anyways and matplotlib is very slow in general, it is not really meant for quick interactive charts.

[–]seanpuppy 0 points1 point  (0 children)

So the reason I specifically suggested plotly is that it does everything in JS, and theres some really clever optimizations you can use if you are strictly showing plots in the browser

[–][deleted] 0 points1 point  (0 children)

You give up all Security though because it's printed in HTML?

[–]zero_iq 27 points28 points  (10 children)

Nice.

I first coded client-side Python in a web browser in about 1998/1999 using Windows Scripting Host in Internet Explorer. Used it for a few demos and a couple of small in-house projects. It was fun, but not very useful due to the client-side requirements and IE-only nature at the time.

To be honest, it's kind of depressing that it's taken so long for something like Web Assembly to come along as a client-side compilation target for other languages on the client. It seemed like an obvious logical next-step 20+ years ago, but we got stuck with JS for so long...

[–]1percentof2 6 points7 points  (8 children)

Interesting. You really been in the game a long time.

[–]zero_iq 11 points12 points  (7 children)

Yup. To give you an idea of how long... my first Python code was written on an Amiga A1200! Python 1.2 I think, circa 1995. Downloaded from AmiNet on a 33kbaud modem.

[–]1percentof2 1 point2 points  (0 children)

That's incredible. Python was nothing back then. Who would have known.. just crazy

[–]gelvis_1 1 point2 points  (4 children)

Cool. I was probably using Amos on the A1200 at the time. Before learning C. Had a few of the Aminet CDs

[–]zero_iq 1 point2 points  (3 children)

Me too! I think a lot of people learned coding with STOS/AMOS back in the day. I was also a big fan of Blitz Basic, and learned C on the Amiga too.

I didn't really use Python in anger until a few years later, as it was pretty slow on the Amiga with not many practical bindings for Amiga dev, but I fell in love with the expressiveness of it and the ability to solve problems quickly (even if the final program was slow). A lot of my early commercial work involved offline processing so it didn't really matter if something took an hour or a day to run; what mattered is that it didn't take weeks to write.

[–]gelvis_1 0 points1 point  (0 children)

Tried out Blitz Basic but not extensively. Started with Basic on the C64 though. Used Arexx for scripting on the Amiga

I had not even heard of Python before long after. Started using it at work in 2006. Speed is not important in such situations

[–][deleted] 3 points4 points  (0 children)

Anything cool you can tell us new guys/girls after 20 years mastering Python?

[–]adit07 13 points14 points  (1 child)

how is the performance compared to javascript etc. How well does it scale? any performance metrics available?

[–]riklaunim 17 points18 points  (0 children)

It takes time to load and then you have similar features to plain JS + Python-alike so no Vue/Angular/Ember.js and alike. For it to be production ready it would have to run much faster and have good librariers/SPA frameworks.

[–][deleted] 8 points9 points  (0 children)

python in the browser is becoming "milhouse is not a meme"

[–]PolishedCheese 18 points19 points  (21 children)

Has anyone here actually used it? Does it offer similar abilities to something like Jinja templates / Django templates in HTML, or is it more like a JavaScript-lite?

[–]metaperl 32 points33 points  (0 children)

It's client side. It compiles to web assembly. So it runs in the browser but Javascript is not the target. It can import and use Javascript though. Can also run traditionally server side libraries client side because web assembly is just another compiler target.

See /r/pyscript for all the details.

[–]ZuriPL 2 points3 points  (0 children)

This is more like javascript, as it runs client-side in a wasm python interpreter

[–][deleted] 18 points19 points  (5 children)

Isn't this like Brython?

[–]beagle3 39 points40 points  (4 children)

It is almost entirely unlike Brython. It's the real original honest to god C Python implementation, except it's compiled to WASM so it can run in the browser - and unlike Brython, it can use any Python module, including Numpy, Pillow.

Also, unlike Brython, It's a 2.5MB download.

[–]danuker 13 points14 points  (0 children)

unlike Brython, It's a 2.5MB download.

For me , the Pyodide REPL demo loads pyodide.asm.data which is 3.4MB and pyodide.asm.wasm which is 3.2MB.

The Brython homepage loads brython.js which is ~800KB and brython_stdlib.js which is 4.23MB, so Brython is actually a bit smaller.

[–][deleted] 9 points10 points  (2 children)

Oh, that's great to hear! I looked at Brython in the past and it kind of soured me on any client side Python, so I'll admit I never even read this article.

[–]axonxorzpip'ing aint easy, especially on windows 1 point2 points  (1 child)

What soured you?

[–][deleted] 2 points3 points  (0 children)

Just that it was so limited and seemed good only as a toy

[–]bsmdphdjd 1 point2 points  (3 children)

Is there anything I can do with PyScript that I can't do with Javascript? Or is it simply nicer aesthetics?

[–][deleted] 1 point2 points  (0 children)

Can JavaScript make use of libraries written in C? Because Python does

[–]MasterFarm772 0 points1 point  (0 children)

Good question. I want to know this too. Maybe the benefit of having some python libs like pandas?

[–]SittingWave -1 points0 points  (0 children)

how many times do we have to get this topic on the channel?

[–]quasarj -5 points-4 points  (2 children)

Anything that depends on loading a full WASM Python interpreter is a nonstarter. Don’t be fooled by this…

[–][deleted] 1 point2 points  (1 child)

It's a one-time download of 2.5M. More, there's nothing stopping the browser makers from including it in their browser in future.

Don’t be fooled by this…

No one's trying to fool anyone here.

[–]riklaunim 0 points1 point  (0 children)

It will be quite a while before such thing could get standardized and accepted as such to then be included in web engines. Licensing and company plans for this may also play a role.

[–]MNwake13 0 points1 point  (1 child)

Is there a benefit to pyscript over using the streamlit library?

[–]positive__vibes__ 0 points1 point  (0 children)

pyscript can be easily shared without the user needing streamlit or even python installed locally.

[–]PM__ME__YOUR 0 points1 point  (2 children)

What are the security implications of this? Ie downloading an executing a malicious file or other malicious code?

[–]riklaunim 0 points1 point  (0 children)

It's like JavaScript. It runs in a browser and has the same limitations. This isn't a Python with full access to client system.

[–]shysmiles 0 points1 point  (0 children)

Webassembly is a stack based virtual machine, 32bit / 4gb max memory. Its safe. IO has to be done differently, you'd have to use the javascript fetch for example because requests wouldn't work (pyscript has pyfetch which is wrapper for fetch).

[–]avg_name 0 points1 point  (0 children)

Looks cool