Is there a way to execute python code in a browser, other than using Jython and an applet?
The execution does not have to deal with anything related to graphics. For example, just sum all the digits of a binary 1Gb file (chosen by the browser user) and then return the result to the server.
I am aware that python can be executed remotely outside a browser, but my requirement is to be done inside a browser.
For sure, I take for granted the user will keep the right to execute or not, and will be asked to do so, and all this security stuff... but that is not my question.
Brython is both a Python compiler and an interpreter written in JavaScript. As a result, you can compile and run Python code in the browser. A good example of this feature is demonstrated by the online editor available on the Brython website. With the online editor, Python is running in the browser.
Using a Chrome Extension – Python Shell. Use the link to download the extension – Python Shell Chrome Extension. Once you have the Python Shell extension installed, proceed to launch it from the extensions manager. You will see a small window pop-up on your browser where you can execute your Python code.
Brython enables us to write and run Python code in the browser by transpiling it to JavaScript. This code will be able to run in all modern browsers supporting JavaScript, because Brython purposely avoids generating JavaScript with new, unsupported syntax. You can think of transpiling as a subset of compiling.
The Pyjamas project has a compiler called pyjs which turns Python code into Javascript.
nosklo's answer is wrong: pyxpcomext for firefox adds language="python" support to script tags. yes it's a whopping 10mb plugin, but that's life. i think it's best if you refer to http://wiki.python.org/moin/WebBrowserProgramming because that is where all known documented links between python and web browser technology are recorded: you can take your pick, there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With