Live data from Hacker News

PyPy.js: Python in the web browser

pypyjs.org

81–90 of 129 posts

Re: PyPy.js: Python in the web browser

#81

Great project. My team used it for a live-coding Python notebook: https://github.com/inkandswitch/livebook#readme To my surprise it was faster than Jupyter / CPython for some tasks (e.g. loading and parsing large CSVs).

Wow, that's awesome! Direct link to the live notebook: https://livebook.inkandswitch.com/fork/welcome

Naturally, I changed the first code block to this:

    from random import randint, seed
    seed()
    "\n".join([randint(5, 25) * ' ' + s for s in ['such code', 'much live', 'wow']])

Re: PyPy.js: Python in the web browser

#85
post #78
post #52

The speed is surprisingly reasonable. Testing with a simple loop, I get about 1.3-1.4 million loops per second in python3, 2 million loops per second in python2, 14.5 million loops in pypy, and 0.61 million loops in the browser. My code basically calls int(time.time()) until its value changes, doing i+=1 for every time it did not change (n=10 for every platform (python2/3/pypy/browser)). My browser is Firefox 61, ful…

Though trying to add the numbers for 1 to a million in a loop javascript was about 10 - 20 times faster when I tried it.

[deleted]

Re: PyPy.js: Python in the web browser

#86

I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?

[deleted]

Re: PyPy.js: Python in the web browser

#87

I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?

    >>> import os
    >>> for root, dirs, files in os.walk('/'):    
    ...   for d in dirs:
    ...     print os.path.join(root, d) + '/'
    ...   for f in files:
    ...     print os.path.join(root, f)
    ... 
    /tmp/
    /home/
    /dev/
    /lib/
    /home/web_user/
    /dev/shm/
    /dev/null
    /dev/tty
    /dev/tty1
    /dev/random
    /dev/urandom
    /dev/stdin
    /dev/stdout
    /dev/stderr
    /dev/shm/tmp/
    /lib/pypyjs/
    /lib/pypyjs/lib_pypy/
    /lib/pypyjs/lib-python/
    /lib/pypyjs/lib_pypy/encodings/
    /lib/pypyjs/lib_pypy/UserDict.py
    /lib/pypyjs/lib_pypy/__future__.py
    /lib/pypyjs/lib_pypy/_abcoll.py
    /lib/pypyjs/lib_pypy/_structseq.py
    /lib/pypyjs/lib_pypy/_weakrefset.py
    /lib/pypyjs/lib_pypy/abc.py
    /lib/pypyjs/lib_pypy/base64.py
    /lib/pypyjs/lib_pypy/code.py
    /lib/pypyjs/lib_pypy/codecs.py
    /lib/pypyjs/lib_pypy/codeop.py
    /lib/pypyjs/lib_pypy/copy.py
    /lib/pypyjs/lib_pypy/copy_reg.py
    /lib/pypyjs/lib_pypy/genericpath.py
    /lib/pypyjs/lib_pypy/getopt.py
    /lib/pypyjs/lib_pypy/linecache.py
    /lib/pypyjs/lib_pypy/os.py
    /lib/pypyjs/lib_pypy/posixpath.py
    /lib/pypyjs/lib_pypy/pwd.py
    /lib/pypyjs/lib_pypy/re.py
    /lib/pypyjs/lib_pypy/repr.py
    /lib/pypyjs/lib_pypy/sre_compile.py
    /lib/pypyjs/lib_pypy/sre_constants.py
    /lib/pypyjs/lib_pypy/sre_parse.py
    /lib/pypyjs/lib_pypy/stat.py
    /lib/pypyjs/lib_pypy/struct.py
    /lib/pypyjs/lib_pypy/traceback.py
    /lib/pypyjs/lib_pypy/types.py
    /lib/pypyjs/lib_pypy/warnings.py
    /lib/pypyjs/lib_pypy/weakref.py
    /lib/pypyjs/lib_pypy/encodings/__init__.py
    /lib/pypyjs/lib_pypy/encodings/aliases.py
    /lib/pypyjs/lib_pypy/encodings/ascii.py
    /lib/pypyjs/lib_pypy/encodings/base64_codec.py
    /lib/pypyjs/lib_pypy/encodings/hex_codec.py
    /lib/pypyjs/lib_pypy/encodings/latin_1.py
    /lib/pypyjs/lib_pypy/encodings/raw_unicode_escape.py
    /lib/pypyjs/lib_pypy/encodings/string_escape.py
    /lib/pypyjs/lib_pypy/encodings/unicode_escape.py
    /lib/pypyjs/lib_pypy/encodings/unicode_internal.py
    /lib/pypyjs/lib_pypy/encodings/utf_16.py
    /lib/pypyjs/lib_pypy/encodings/utf_8.py
    /lib/pypyjs/lib-python/2.7/

Re: PyPy.js: Python in the web browser

#88
post #76
post #75

File " ", line 2 return f'{fname} {surname} is {age}.' ^ SyntaxError: invalid syntax So this is a subset of Python or something like that?

I believe this feature was introduced in Python 3.6. This implementation may be 3.6 Edit: Just checked the site and see it uses PyPy which states -- on their site -- the python version is 3.5.3

I can't do:

a, *b = range(3)

which should be 3.5 i think.

Re: PyPy.js: Python in the web browser

#89
post #52

The speed is surprisingly reasonable. Testing with a simple loop, I get about 1.3-1.4 million loops per second in python3, 2 million loops per second in python2, 14.5 million loops in pypy, and 0.61 million loops in the browser. My code basically calls int(time.time()) until its value changes, doing i+=1 for every time it did not change (n=10 for every platform (python2/3/pypy/browser)). My browser is Firefox 61, ful…

Which version of python 3 did you test with? I expected 3.6+ to be faster than python 2.7

Re: PyPy.js: Python in the web browser

#90
Really amazing. I use python every day at work, and most of the crucial libraries have tight inner loops written in C or Cython. I wonder what the web assembly future holds for those languages, and inter-language FFI.
Post reply on HN