Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute python code inside browser without Jython

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.

like image 523
proportional Avatar asked Aug 05 '09 20:08

proportional


People also ask

Can you run Python code on a browser?

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.

How do I run Python code in Chrome?

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.

What permits us to write Python code that can run in the browser?

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.


2 Answers

The Pyjamas project has a compiler called pyjs which turns Python code into Javascript.

like image 182
Alexander Ljungberg Avatar answered Oct 01 '22 23:10

Alexander Ljungberg


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.

like image 36
user362834 Avatar answered Oct 01 '22 23:10

user362834