Execute python code inside browser without Jython
Asked Answered
M

10

19

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.

Merilee answered 5/8, 2009 at 20:43 Comment(8)
I assume that a local installation of python is on client side.Merilee
You need to install the Python Win32 extensions on the client and you'll be able to use Python the same way you use VBScript and JScript.Whitman
Can I ask what is it you are looking for? Why it has to run client side on a browser? May be you need another tool. Either a client application/script or server side code.Whitman
Would you please clarify your question: (1) What browsers must be supported? IE-only? (2) What client OS must be supported? Windows-only ? (3) What sorts of browser plugins can be used in a solution? Adobe? Silverlight? A custom plugin, that must be installed on each system?Paddle
Answer(1): I want as many browsers as possible. At least: Firefox, Chrome, Safari, IExplorer, Opera. Answer(2): At least: Linux (all flavours), Windows XP SP2 and followers, MacOS Answer(3): Any that may answer my question. Yes, a custom plugin may be installed by the client.Merilee
The point to be run in a browser is that in many enviroments users do not have the right to install anything but in the browser.Merilee
Another point I was missing about running inside a browser is the example of my question: to let the client do the hard work and not overload the server.Merilee
Another point is that HTML5 is well suited to building user interfaces, while Python's GUI tools are absolute shite.Longterm
R
9

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

Restraint answered 5/8, 2009 at 21:10 Comment(2)
Look at proportional's comment in my answer.Whitman
Yep, he'd run into the sandbox problem.Restraint
C
6

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.

Cultism answered 9/6, 2010 at 20:7 Comment(0)
V
6

I put together a table comparing many Python-In-Browser technologies not long ago: http://stromberg.dnsalias.org/~strombrg/pybrowser/python-browser.html

Vish answered 26/7, 2013 at 18:56 Comment(1)
It's back up now. My internet connection had problems this morning.Vish
T
4

On my travels, I came across Skulpt, a project which seems to offer Python directly in the browser without plugins. It's licensed under MIT.

Skulpt Homepage

Skulpt @ Github

Turaco answered 10/4, 2013 at 9:14 Comment(0)
M
3

No, you can't.

Modern browsers only run javascript or plugins. You can develop your own python plugin and convince people to download and run it, but I guess that falls to the "not inside the browser" category.

Moonrise answered 5/8, 2009 at 20:50 Comment(4)
Silverlight, Flash, Java (Jython) are all plugins - the browser DOES NOT execute python.Moonrise
It may fall in "inside browser" category for me if there is such a plugin that the browser can launch.Merilee
you can write a plugin to run python. convincing the user to install it is another matter.Moonrise
Yes, of course. As I stated in my question, that worries me not.Merilee
P
3

You mean client-side?

Sure you can! But you need to have python installed on the client first.

The linked book describes that in order to use client-side Active Scripting, you can test it with the a simple html file.

<html><body>
<script language='Python'>alert("Hello, Python!")</script>
</body></html>

In the old version refered in that book (Python programming on Win32 By Mark Hammond, Andy Robinson) it says that you need to install the Python Win32 extensions, and it will automatically register Python Active Scripting. Should you do it manually, you have to run the script python\win32comext\axscript\client\pyscript.py.

Paucker answered 5/8, 2009 at 20:50 Comment(3)
Don't know status for FF, and can't test as I blow my Windows VM :SWhitman
Good try, but in page 438 of your reference says that IE won't let python open nor local files neither sockets. I wonder what happens with other browsers not in the Redmond side.Merilee
You are correct, you will be sandboxed, just like with JScript and VBScript. You can use it as a replacement for javascript, but I don't think it's worth the effort. You still have to use your server for low level (file, socket, etc.) operations. Can I ask what is it you are looking for? Why it has to run client side on a browser? May be you need another tool. Either a client application/script or server side code.Whitman
Q
3

http://repl.it/ - Python interpreter in JavaScript running on client side. There are many other languages too. Source is available under MIT license, which is awesome.

Quoth answered 22/5, 2012 at 11:40 Comment(0)
J
3

You can now (2016) also use:

http://www.transcrypt.org

It compiles Python 3.6 (incl. multiple inheritance, operator overloading, all types of comprehensions, generators & iterators) to lean and fast JS, supports source level debugging with sourcemaps and optional static typechecking using mypy.

Disclaimer: I am the initiator of the project.

Jerad answered 3/10, 2016 at 10:37 Comment(0)
I
2

By accident I was listening to Hanselminutes where he mentioned about Gestalt project. This is a solution to integrate a languages as IronRuby and IronPython in browser via Silverlight.

So I think the answer is no if you don't have any special plugins.

Idiolect answered 5/8, 2009 at 20:53 Comment(0)
D
2

Brython - "A Python 3 implementation for client-side web programming"

Dori answered 8/12, 2013 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.