8 ms·
I've looked into Brython and other "Python in the browser" implementations (transcrypt.org, pypyjs.org). It's fun! At a high level, the approaches are: * Crea
by mshenfield 6y ago
I've looked into Brython and other "Python in the browser" implementations (transcrypt.org, pypyjs.org). It's fun! At a high level, the approaches are:
* Create a Python interpreter that is able to run Python code directly in the browser (PyPy.js, Brython)
* Transpile Python code into JavaScript and send that to the browser (Transcrypt, which also does a lot of tree shaking to keep the transpiled code efficient).
Here are the benefits, IMHO:
* Share helper code and class definitions across environments
* Most of the std lib, and a handful of popular 3rd party libs, are supported
* In the rare happy path, only have to think about one programming language.
The downsides are:
* Slow. For the "send an interpreter" approach (Brython, PyPy.js), the browser has to compile a whole compiler before moving on to running your code.
* Incompatibilities. For Brython and Transcrypt, C parts of the standard lib have to be re-written in Python for compatibility. So when you're importing something from the itertools package, it's actually a custom implementation like this: https://github.com/brython-dev/brython/blob/master/www/src/Lib/itertools.py https://github.com/brython-dev/brython/blob/master/www/src/L.... The custom code will not always be exactly compatible with the CPython implementation.
* Incompleteness. Some std libs aren't implemented, or are only partially implemented. 3rd party libs that rely on these will not work. Popular 3rd party libs like sklearn which get their power by wrapping C/Fortran libraries need custom wrappers that don't exist (AFAIK) yet.
* You still gotta JavaScript. Even in the best transpilation scenarios, things break and you have to figure out what the generated or interpreted code is doing. This is especially tough for Python in the browser tools, which aren't widely used, so have both undiscovered bugs and a lack of community support. In my experience, working in a transpiled codebase doesn't mean you have to learn one thing, but three: the source language, the target language, and the frankenstein monster of the logic/compromises bridging the two.
* Tooling. The ecosystem hasn't reached a critical mass to support tooling. It's unclear if there's enough excitement in the Python community to get it there.
With all that said, unless you're a true believer or just want to have a little fun (again, it is fun!), I wouldn't recommend this.