Thursday, August 13th, 2009

Skulpt: Crazy project that lets your browser parse and run Python

Category: Python

Skulpt is an entirely in-browser implementation of Python.

Really. Crazy and cool.

You can build an example term like this just via:


  1. window.addEvent('domready', function() {
  2.     var term = initTerminal(80, 20);
  4.     // set up demo typers
  5.     $('codeexample1').addEvent('click', (function(e)
  6.             {
  7.                 e.stop();
  8.                 term.doClear();
  9.                 term.writeStr("print \"Hello, World!\"     # natch", false, true);
  10.                 term.doEnter();
  11.             }));
  12.     $('codeexample2').addEvent('click', (function(e)
  13.             {
  14.                 e.stop();
  15.                 term.doClear();
  16.                 term.writeStr("for i in range(5):", false, true); term.doEnter();
  17.                 term.writeStr("    print i", false, true); term.doEnter();
  18.                 term.doEnter();
  19.             }));
  20.     $('codeexample3').addEvent('click', (function(e)
  21.             {
  22.                 e.stop();
  23.                 term.doClear();
  24.                 term.writeStr("[x*x for x in range(20) if x % 2 == 0]", false, true);
  25.                 term.doEnter();
  26.             }));
  28.     term.writeStr("Skulpt demo REPL - " + new Date().toLocaleString() + "\n");
  29.     term.writeStr(term.PS1, true);
  30. });

Posted by Dion Almaer at 6:59 am

4.2 rating from 39 votes


Comments feed TrackBack URI

Who’s up to the challenge of creating a ruby version?

Comment by sixtyseconds — August 13, 2009

Pretty brilliant. With all these languages-within-a-browser project, I wonder how far we are from having Javascript emulate Java, which could then run a browser? :)

Comment by ilithium — August 13, 2009


Looks like someone already did:

Fun stuff.

Comment by smith — August 13, 2009

Guess what, US keyboard layouts aren’t used worldwide. Some people like their quotes as shift+2.

Comment by Darkimmortal — August 13, 2009

This has the potential to be all kinds of awesome. I would so much rather my browser code be Python than Javascript. My reasons are mostly cosmetic (I think Python is much cleaner than JS), but still it would be nice to have flexibility in the browser world.

Comment by tercero12 — August 13, 2009

“Guess what, US keyboard layouts aren’t used worldwide. Some people like their quotes as shift+2.”

The guy writes an early-release language-in-a-browser and you complain about localization? Harsh I’d have thought.

Can’t honestly think when I’d use this, but its pretty neat all the same.

Comment by kissmyawesome — August 13, 2009

Nice work. This is really cool!

@ilithium I thought I saw a java interpreter in javascript once, although I can’t find it anymore.

Comment by devongovett — August 13, 2009

I want to know how he did it. Surely he didn’t write a Python interpreter from scratch in javascript?!

Comment by JonathanLeech — August 13, 2009

Now someone produce a JavaScript interpreter in Python, then we can recursively run these recursively inside each other until the universe explodes.

Comment by Amtiskaw — August 13, 2009

“I want to know how he did it. Surely he didn’t write a Python interpreter from scratch in javascript?!”

I looked at the source. It looks like he did.

Comment by Nosredna — August 13, 2009

JavaScript is already quite inefficient, but JavaScript executing another language? This is surely going to be quite slow, if it works.

My (very unlikely to occur) dream is that the browsers unite on a virtual machine with bytecode and a DOM interface, something like Parrot which can still execute JavaScript as well as Python, Perl6, Ruby, Lua, and tons of other programming languages concurrently.

Comment by jhuni — August 13, 2009

jhuni, bytecode is my nightmare. Once you have bytecode, you lose the ability for people to learn from looking at the source other people write.

Comment by Nosredna — August 13, 2009


Comment by stoimen — August 14, 2009

I hate to be the voice of grumpiness, but aside from the “oo, look what you can make JavaScript do” factor, what possible use does this have?

Comment by timdown — August 14, 2009

RE: jhuni, bytecode is my nightmare. Once you have bytecode, you lose the ability for people to learn from looking at the source other people write.

You already lose that by minification and obfuscation that most production environments implement anyways. It might as well be bytecode. Besides Flash also exists all over production environments and you cannot read its source code either.

Just because bytecode would exist doesn’t mean you couldn’t send JavaScript over anyways and then the JavaScript can get converted to bytecode by the client rather then the server. The advantage is you could also send over Python, Perl, or Ruby so you would not have to use a poorly designed language called JavaScript.

Comment by jhuni — August 14, 2009

Just started to learn python yesterday in order to use the Google App Engine. Not sure if this is useful but certainly going to have a play around with it.

Comment by McDaid — August 14, 2009

Which would imply that Python/Ruby/Perl aren’t badly designed? (Rhetorical question)

Comment by TNO — August 14, 2009

Well I did not necessarily say that Python/Ruby/Perl are designed effectively, it is more that between such languages most people could find something they like better then JavaScript.

Comment by jhuni — August 14, 2009

Indeed, some other crazy guy already made a Ruby virtual machine in Javascript ages ago.

But there are also languages that were explicitely designed to support multiple other languages as targets, including Javascript. haXe ( ) is the best example I can think of, but there must be other ones. haXe can compile for its own VM (Neko) but the same source code can also be translated into C++ (that can even build native iPhone applications), Javascript, PHP and Flash. It’s quite convenient, especially to share code between the client side and the server side.

Comment by axey — August 15, 2009

My favourite langauge-in-javascript is the 6502 compiler: – I just tried it again after seeing this page. Thanks to our new kick-arse JS engines it runs a zillion times faster.

It’s like when you find old games that were made for a 386 where the timing was set to “show as many frames per second as possible”. You think we would have learned the first time ;)

Comment by mrspeaker — August 16, 2009

Its sad how we could make the web browser a million times better, but we don’t. You would think competition might be a reason for it to improve. It is not.

Comment by jhuni — August 17, 2009

Projects like this one illustrate the idiocy of Python’s decision to impart semantic meaning to whitespace. It’s one thing for a *person* to indent code properly in a text editor, and another entirely when the code “writer” is another program.

Comment by hjess — August 18, 2009

Leave a comment

You must be logged in to post a comment.