(don't bash me too hard) Python interpreter in JavaScript

P

Passiday

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order to provide a web-based application with python scripting capabilities. The app would have basic IDE for writing and debugging the python code, butthe interpretation, of course, would be done in JavaScript. I'd like to avoid any client-server transactions, so all the interpretation should take place on the client side. The purpose of all this would be to create educational platform for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up anything. I've found some crazy project emulating PC in JavaScript (and even running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, but that seems like awful lot of work to do. Any ideas how I should proceed with this project?
 
C

Chris Angelico

The app would have basic IDE for writing and debugging the python code, but the interpretation, of course, would be done in JavaScript. I'd like to avoid any client-server transactions, so all the interpretation should takeplace on the client side. The purpose of all this would be to create educational platform for learning the programming in python.

Hmm. If it's to be an educational platform, I would recommend doing
something like the W3Schools "tryit" page [1] and just go back to the
server each time. You have potential security issues to watch out for
(so it may be worth chrooting your interpreter), but it's sure to be
easier than rewriting the entire interpreter in another language. You
would have to maintain your implementation as the language evolves,
keep it bug-free, etc, etc.

ChrisA

[1] eg http://www.w3schools.com/html/tryit.asp?filename=tryhtml_basic
 
I

Ian Kelly

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order to provide a web-based application with python scripting capabilities.. The app would have basic IDE for writing and debugging the python code, but the interpretation, of course, would be done in JavaScript. I'd like to avoid any client-server transactions, so all the interpretation should takeplace on the client side. The purpose of all this would be to create educational platform for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up anything. I've found some crazy project emulating PC in JavaScript (and even running Linux on top of it), but not a python interpreter.

You could take a look at pyjamas, but it's precompiled. I don't know
whether they have support for runtime compilation at all.
 
S

Stef Mientki

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order to provide a web-based application with python scripting capabilities. The app would have basic IDE for writing and debugging the python code, but the interpretation, of course, would be done in JavaScript. I'd like to avoid any client-server transactions, so all the interpretation should take place on the client side. The purpose of all this would be to create educational platform for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up anything. I've found some crazy project emulating PC in JavaScript (and even running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, but that seems like awful lot of work to do. Any ideas how I should proceed with this project?
skulpt ?

cheers,
Stef
 
T

Terry Reedy

You could take a look at pyjamas, but it's precompiled. I don't know
whether they have support for runtime compilation at all.

Perhaps one could use pyjamas to compile pypy to javascript ;-).
 
A

Alan Meyer

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order to provide a web-based application with python scripting capabilities. The app would have basic IDE for writing and debugging the python code, but the interpretation, of course, would be done in JavaScript. I'd like to avoid any client-server transactions, so all the interpretation should take place on the client side. The purpose of all this would be to create educational platform for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up anything. I've found some crazy project emulating PC in JavaScript (and even running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, but that seems like awful lot of work to do. Any ideas how I should proceed with this project?

I don't have any good ideas for how to do this, but I do have a warning.
The JavaScript security model prohibits a lot of things that Python
does not prohibit. So if you need to do anything like access a file on
the user's machine or talk to some computer other than the one you came
from, it won't work.

Alan
 
C

Carl Banks

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order to provide a web-based application with python scripting capabilities.. The app would have basic IDE for writing and debugging the python code, but the interpretation, of course, would be done in JavaScript. I'd like to avoid any client-server transactions, so all the interpretation should takeplace on the client side. The purpose of all this would be to create educational platform for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up anything. I've found some crazy project emulating PC in JavaScript (and even running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, but that seems like awful lot of work to do. Any ideas how I should proceed with this project?


Some people have already made an LLVM-to-Javascript compiler, and have managed to build Python 2.7 with it.

The LLVM-to-Javascript project is called emscripten.

https://github.com/kripken/emscripten/wiki

Demo of Python (and a bunch of other languages) here:

http://repl.it/


Carl Banks
 
P

Passiday

Of course, I am aware of this. But the file system can be emulated, and certain networking can be mediated via the server, too. But for starts, I don't plan to go beyond the basic file operations, if at all.
 
O

OKB (not okblacke)

Carl said:
Some people have already made an LLVM-to-Javascript compiler, and
have managed to build Python 2.7 with it.

The LLVM-to-Javascript project is called emscripten.

https://github.com/kripken/emscripten/wiki

Demo of Python (and a bunch of other languages) here:

http://repl.it/

Very interesting. Is there a simple way to add third-party
libraries to these? I assume that for pure-Python modules you could
just put a python file in the appropriate place and import it, but what
about if you wanted a web app that used numpy or something? Is that
feasible?

--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
 
A

Alec Taylor

Just compile your python to C

:]

       Very interesting.  Is there a simple way to add third-party
libraries to these?  I assume that for pure-Python modules you could
just put a python file in the appropriate place and import it, but what
about if you wanted a web app that used numpy or something?  Is that
feasible?

--
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
       --author unknown
 
L

Lorenzo

        Very interesting.  Is there a simple way to add third-party
libraries to these?  I assume that for pure-Python modules you could
just put a python file in the appropriate place and import it, but what
about if you wanted a web app that used numpy or something?  Is that
feasible?

I cannot imagine how slow can be a python interpreter in javascript
crunching numbers using numpy, and converting those numeric libraries
(ATLAS, LAPACK,MKL,ACML) to javascript.
 
B

becky_lewis

Hello,

I am looking for a way how to bring Python interpreter to JavaScript, in order to provide a web-based application with python scripting capabilities.. The app would have basic IDE for writing and debugging the python code, but the interpretation, of course, would be done in JavaScript. I'd like to avoid any client-server transactions, so all the interpretation should takeplace on the client side. The purpose of all this would be to create educational platform for learning the programming in python.

I hoped somebody already had done something like this, but I couldn't google up anything. I've found some crazy project emulating PC in JavaScript (and even running Linux on top of it), but not a python interpreter.

Of course, I could take the python source and brutally recode it in JavaScript, but that seems like awful lot of work to do. Any ideas how I should proceed with this project?

I think you may find it a little time consuming to reimpliment python
in javascript. I'm inclined to say "go for it" though since you may
create something awesome in the process ;)

If you want to take an easier route, may I point out
pythonanywhere.com? It doesn't run in the browser but does give safe
access to multiple python interpreters and from my own use I can say
that it works pretty well. You can even set up web apps using it. For
educational purposes it might be helpful to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top