PyScript, a new kid on the block

389 views
Skip to first unread message

Kiko

unread,
Apr 30, 2022, 5:16:34 PM4/30/22
to brython
Hi everyone,

Just FYI.

This has been presented in PyConUS2022 by Anaconda:

https://pyscript.net/

Kind regards,

Pierre Quentel

unread,
May 1, 2022, 8:04:36 AM5/1/22
to brython
Thanks for the pointer Kiko.

I am not surprised that Anaconda is working on this: the CEO contacted me to work on a Python-in-the-browser project a few weeks ago (I declined, mostly because I don't want to have a manager or manage a team myself any more ;-). But I am impressed that they were able to present a keynote so early.

I have taken a look at the examples at https://pyscript.net/examples/. They take generally a few seconds to start: this is because the platform relies on an implementation of Python in WASM (pyodide). It has been the same issue with pyjs.js a few years ago : they are fully compatible with CPython, but the performance cost is currently high.

Another issue is that the code inside <py-script> tags is not real Python. For instance, in the simple_clock example, the code is

from utils import now
import asyncio

async def foo():
  while True:
    await asyncio.sleep(1)
    output = now()
    pyscript.write("outputDiv2", output)

    out3 = Element("outputDiv3")
    if output[-1] in ["0", "4", "8"]:
      out3.write("It's espresso time!")
    else:
      out3.clear()

pyscript.run_until_complete(foo())


The names pyscript and Element seems to be magically inserted in the script namespace, without being imported. In my experience (almost 10 years !), Python developers want real Python, not a Python-like language.

That being said, good luck to py-script ! With the support of a company and dedicated resources, the current issues may be solved shortly. And anyway, it gives a new impulse to the main goal behind Brython : bring Python to the browser.

 

Kiko

unread,
May 1, 2022, 2:11:38 PM5/1/22
to bry...@googlegroups.com
2022-05-01 14:04 GMT+02:00, Pierre Quentel <pierre....@gmail.com>:
>
>
> Le samedi 30 avril 2022 à 23:16:34 UTC+2, kiko (on pybonacci) a écrit :
>
>> Hi everyone,
>>
>> Just FYI.
>>
>> This has been presented in PyConUS2022 by Anaconda:
>>
>> https://pyscript.net/
>>
>> Kind regards,
>>
>
> Thanks for the pointer Kiko.
>
> I am not surprised that Anaconda is working on this: the CEO contacted me
> to work on a Python-in-the-browser project a few weeks ago (I declined,
> mostly because I don't want to have a manager or manage a team myself any
> more ;-). But I am impressed that they were able to present a keynote so
> early.

Actually it is pyodide under the hood. All the pieces were there since
a while. I already have an IDE example in my site since more than a
year using numpy, matplotlib and all the scientific goodness of
Python.

>
> I have taken a look at the examples at https://pyscript.net/examples/. They
>
> take generally a few seconds to start: this is because the platform relies
> on an implementation of Python in WASM (pyodide). It has been the same
> issue with pyjs.js a few years ago : they are fully compatible with
> CPython, but the performance cost is currently high.

The PyOdide folks are working on this and they already have reduced
the size of the files in a 35% if I remember correctly. But yes, there
is a lot of work to do.

Maybe, something like this, optimized, could be included in browsers
in the near future so you do not depend on tens of Mbs of downloads.
But this is something political (Google + MS + Apple + Mozilla +
Standards + ...).

>
> Another issue is that the code inside <py-script> tags is not real Python.
> For instance, in the simple_clock
> <https://pyscript.net/examples/simple_clock.html> example, the code is
>
> from utils import now
> import asyncio
>
> async def foo():
> while True:
> await asyncio.sleep(1)
> output = now()
> pyscript.write("outputDiv2", output)
>
> out3 = Element("outputDiv3")
> if output[-1] in ["0", "4", "8"]:
> out3.write("It's espresso time!")
> else:
> out3.clear()
>
> pyscript.run_until_complete(foo())
>
> The names pyscript and Element seems to be magically inserted in the script
>
> namespace, without being imported. In my experience (almost 10 years !),
> Python developers want real Python, not a Python-like language.

Definitely, this is not pythonic at all. I think this is very
premature and it will evolve in a much better way. PyOdide has a
'browser' lib but you have to import it explicitly. I do not know what
they are doing here. Maybe this summer I will dig a little bit into
PyScript to better understand what it is offering.

>
> That being said, good luck to py-script ! With the support of a company and
>
> dedicated resources, the current issues may be solved shortly. And anyway,
> it gives a new impulse to the main goal behind Brython : bring Python to
> the browser.
>

Yay!!! Let's see all the resources Anaconda could put into this and
how it evolves.

>
>
> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/17bdcfcd-e661-4701-87a1-09fc2dd224f9n%40googlegroups.com.
>

Pierre Quentel

unread,
May 1, 2022, 4:11:38 PM5/1/22
to brython
I made a test with the scripts available from a CDN (couldn't use the zip file, the scripts pyscript.css and pyscript.js seem to be missing) and ran this simple loop

import time
t0 = time.time()
for i in range(10_000_000):
  pass
print(time.time() - t0)

It takes 7.71 seconds with pyscript, compared to 0.11 seconds with Brython.

Another example:

for i in range(1_000_000):
    def f(x, y=1, *args, **kw):
        pass

2.66 secs for pyscript, 0.58 secs for Brython.

This is a very limited benchmark, but it's intriguing.

If some users can try with other examples I would be interested.

Kiko

unread,
May 1, 2022, 5:22:26 PM5/1/22
to bry...@googlegroups.com
Here you have a page with examples (i do not get why it is not linked
in the main page):
https://pyscript.net/examples/

The 'Hello World' example
(https://pyscript.net/examples/hello_world.html) downloads 18.5Mb
(9.05Mb for pyodide.asm.wasm, 5.14Mb for pyodide.asm.data, 1.91Mb for
pyodide.asm.js, 1.15Mb for pyscript.js,...). ATM, to me this is a
no-go for a public web app. I can think of desktop apps or web-apps in
corporative local networks where it can have sense to deploy 'desktop
apps' that can be used in the browser.

if this: pyodide.asm.wasm+pyodide.asm.data+pyodide.asm.js was included
in the browser by default then it will make a lot of sense.

OTOH, the login page for twitter is downloading 8.63Mb :-O so who
knows... Crazy web times.

Yes, the zip file is not very useful. It seems they prepared something
that it is in beta stage for the talk in the PyConUS. Maybe they get
confirmation for the talk very late. I don't know. I think things will
improve in the near future as they are pretty capable.

In the past I did data intensive tests comparing pyodide + numpy (etc)
Vs CPython + numpy (etc) and pyodide was slower. CPython was 1.5x or
2x faster (quite impressive IMHO). I have not tested web stuff (DOM,
etc) using PyOdide.

> --
> You received this message because you are subscribed to the Google Groups
> "brython" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to brython+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/brython/1f17220a-623d-480e-b01f-49c74063435dn%40googlegroups.com.
>

Kiko

unread,
May 2, 2022, 3:03:41 AM5/2/22
to bry...@googlegroups.com
It seems Anaconda is also sponsoring Beeware trying to resurrect their
Toga web backend:
https://beeware.org/news/buzz/april-2022-status-update/

Maybe it is a boost for python in android/ios/web frontend? Let's see.

J M E

unread,
May 6, 2022, 7:33:12 AM5/6/22
to bry...@googlegroups.com
Have to say I was underwhelmed by the release. Seems extremely rushed with lots and lots that does not work. See the list of woes in the Github issues. First impressions die hard!

Reply all
Reply to author
Forward
0 new messages