
Skulpt: client side Python without preprocessing - galfarragem
http://www.skulpt.org/
======
primitivesuave
Many people, especially kids, will at some point encounter an online learning
tool where you can just run Python in the browser. Chances are the underlying
interpreter is Skulpt. A short list of examples:

\- [https://pythonroom.com](https://pythonroom.com): has a free online
curriculum with more helpful error messages that kids can understand and real-
time analytics for teachers

\- [https://trinket.io](https://trinket.io): handles Python, turtle graphics,
and pygal charting in the browser

\- [https://tynker.com](https://tynker.com): their Python notebook feature
uses Skulpt

\- [http://interactivepython.org](http://interactivepython.org): a popular
open-source textbook that has excellent Parson's problems

\- [http://codeskulptor.org](http://codeskulptor.org): implements some custom
Skulpt libraries that I haven't seen anywhere else

\- [https://www.coursera.org/learn/interactive-
python-1](https://www.coursera.org/learn/interactive-python-1): Coursera's
interactive Python course

That's just the ones I could remember off the top of my head. I truly believe
this is one of the most impactful open-source projects of all time, especially
if you consider the impact is has on kids (i.e. future computer scientists)
that can use an excellent teaching language like Python directly in their web
browser.

~~~
sametmax
Python dev and trainer here.

Skulp is terrible as a python implementations go. Error reporting is meh. Many
advanced features are not supported.

Brython is a much better alternative. More complete and robust.

However, i advise against running a js python in general. Exposing secured and
isolated jupyter notebooks is much better for learning.

~~~
eah13
I think it's important to distinguish user groups. No solution is best for all
of them.

For scientists or data analysts, jupyter notebooks are a great choice since
they mirror the professional and research tools they'll use.

For web development, an in-browser IDE like Cloud9 would be my choice to get
an arbitrary room of adults up to speed.

But for middle or high school audiences, or even adult beginners, solutions
like the above are far too complex. It's easy to get a certain expert
blindness, but a Jupyter notebook for instance can actually be a huge problem
form someone trying to understand flow of control, since you can execute code
blocks in an arbitrary order into the same runtime.

Tradeoffs between power and usability abound. Jupyter is a good blend. A full
IDE is power. Skulpt prioritizes usability. Some group of users fits into each
of these buckets.

So (surprise, surprise!) The meanings of 'best' and 'terrible' are highly
dependent upon specific user needs.

~~~
sametmax
> Jupyter notebook for instance can actually be a huge problem form someone
> trying to understand flow of control, since you can execute code blocks in
> an arbitrary order into the same runtime.

True. I usually don't let them know they can create several cells first. They
use only one for a good part of the show.

Skulpt will lead to strange debugging sessions, and you really, really want
them to learn how to debug autonomously asap. So having the same stacktrace in
every env is very important.

------
meredydd
Hi there! One of the Skulpt maintainers here. (Also founder of Anvil -
[https://anvil.works](https://anvil.works). Never thought I'd have two
projects on the front page at once!)

Feel free to ask any questions about the gory internals and how it works. You
might also enjoy my talk from PyCon US this summer, about how Skulpt compiles
blocking Python code into non-blocking Javascript:
[https://anvil.works/blog/pycon-talk](https://anvil.works/blog/pycon-talk)

~~~
primitivesuave
Thank you for building such a fantastic tool that has gotten so many more
people coding in Python.

~~~
meredydd
Thank-you! It's definitely a team effort, including several educators as well
as the teams from Trinket and Anvil (where I'm a cofounder). A particular
shout-out for Albert-Jan Nijburg, who does some contracting for Trinket but
donates a lot of his own time to the project. (I think we're top two
contributors at the moment, but this varies a lot - we also get summer
students who are very helpful.)

~~~
eah13
I can second this sentiment. Meredydd and Albert Jan have made a good deal of
Skulpt's most technically interesting features (which in turn enable a more
seamless user experience). I'm a cofounder of Trinket and we knew early on
that this project was something we would use heavily and wanted to support. We
support more languages now (including server side Python, Java, and with R
coming soon) but our skulpt-based free Python trinket remains our most popular
one.

Our users have benefitted hugely from contributions by Meredydd, Albert Jan,
Michael Ebert, Marie Chatfield, Scott Rixner, Brad Miller, and a whole bunch
of other contributors. Go team!

------
eah13
I'm a co-founder of Trinket and thought I'd explain why we chose Skulpt.

Client-side execution lets you do visual things that would be slow and
complicated (maybe practically impossible) if you ran them server side. Visual
results are one of the most important motivators for students learning to
code.

Take our Sense HAT emulator, made in partnership with Raspberry Pi:

[https://trinket.io/sense-hat](https://trinket.io/sense-hat)

This uses 3D CSS and SVG to make a virtual Raspberry Pi that you can rotate
around. The Sense HAT has a gyroscope, accelerometer, etc that kids can
actually program to respond to these movements.

The alternative to this emulator was the Raspberry Pi Foundation sending boxes
of computers to classrooms (which they still do). But the emulator makes this
scalable while also synergizing with the computers: kids can download their
code and run it on the real device if they want.

The next phase in the project is letting kids run their code in space. Mission
Zero uses the emulator to let European kids get their code run on one of the
Raspberry Pis in orbit on the International Space Station:

[https://trinket.io/mission-zero](https://trinket.io/mission-zero)

Skulpt makes this possible.

Why not Brython or RapydScript? Theoretically, either could do most of this.
Skulpt is designed for the needs of teachers and learners. Those projects have
slightly different goals (making Python a web scripting language and providing
a Pythonic way to write JS, respectively) which may make them a better fit for
your project but we've found Skulpt to meet our users' needs the best. Our
users are teachers and students in middle and high school, and some
undergrads, who want to write, run, and share programs and websites as quickly
and easily as possible. They need reasonable speed, fidelity to Python and
lots of fun visuals. Turtle, Matplotlib, and now the Sense HAT emulator
provide the visuals.

Skulpt isn't perfect but it's got a great community and is getting better all
the time. I think it's the clear best choice if your users are teaching or
learning. And projects like Anvil (anvil.works) show how the project can work
outside of education as well, in that case for non-specialist business
analysts/ops people who would otherwise be stringing together spreadsheets.

------
pgbovine
creator of [http://pythontutor.com/](http://pythontutor.com/) here ... skulpt
is great and i know one of its maintainers quite well. one use case that's
important is using it to distribute self-contained zero-install tutorials onto
computers such as school machines and those in less-well-resourced parts of
the world without good Internet access. you can deliver an HTML/CSS/JS zip
file on a USB stick or CD-ROM and get lessons up and running even without
Internet access.

that said, though, one reason I haven't made the plunge to Skulpt and still
choose to run Python server-side is that as students get more advanced, they
will inevitably run into edge cases and other weird behavior where skulpt will
not match CPython, and the error messages and other outputs they get will
become inconsistent with expectations. that's why i still continue to run
CPython server-side in a sandbox for
[http://pythontutor.com/](http://pythontutor.com/)

------
meredydd
Urk! Albert-Jan is busily trying to wake someone up and get the site back up.
Meanwhile:

Archive link: [http://archive.is/leOnD](http://archive.is/leOnD)

GitHub: [https://github.com/skulpt/skulpt](https://github.com/skulpt/skulpt)

------
cafogleman
Hacker News strikes again. I'm receiving a '503 Over Quota' from the site
right now.

~~~
eah13
[https://github.com/skulpt/skulpt](https://github.com/skulpt/skulpt) while you
wait

~~~
tim333
Or the Google cache
[http://webcache.googleusercontent.com/search?q=cache:6RzAnju...](http://webcache.googleusercontent.com/search?q=cache:6RzAnjuDojsJ:www.skulpt.org/+&cd=1&hl=en&ct=clnk&gl=uk)

------
eigengrau
How does this compare to Brython
([http://brython.info/](http://brython.info/)), apart from missing the Python
3 support? Are there any custom bindings to the browser API?

~~~
meredydd
I think it's mostly a difference in approach. Brython sets out to "replace
Javascript with Python" as the language of scripting the Web. This means it
has custom bindings to the browser API, supports writing Brython in <script>
tags, uses slightly funky/un-Pythonic operators to do DOM manipulation, etc.
Brython code can't block, to my knowledge (although the Python 3 async stuff
makes that constraint much less painful these days).

Skulpt is "a Python implementation in JS". It doesn't have built-in DOM
bindings - it's typically used within a project like Anvil or Trinket which
provides higher-level (and therefore more Pythonic) modules for
display/input/IO. Skulpt code can block, which also helps keep those APIs
simple.

I guess my summary would be that Brython is great for scripting your HTML in
Python rather than Javascript, but Skulpt is best for providing a Python
runtime in your app. Does that make sense? (Of course, you'd have to ask a
Brython developer for their take on it ;) )

~~~
azag0
Why the quotes around "Python implementation in JS"? Isn't it literally just
that?

~~~
meredydd
They're quotes from each respective project's homepage :)

------
tim333
Archive link if you get a 'Over Quota':
[https://web.archive.org/web/20171027212510/http://www.skulpt...](https://web.archive.org/web/20171027212510/http://www.skulpt.org/)

------
amelius
How long until we can compile Python to Web-assembly?

EDIT: I just realized this can mean two things:

1\. Compiling python source code to Web-assembly.

2\. Compiling the python interpreter/compiler to Web-assembly.

~~~
albertjan
(Contributor to skulpt and pypy.js here)

That is a difficult question to ask and I think the original developer of
pypy.js Ryan Kelly is most suited to answer it. There are some people that
have tried feeding the asm.js from pypy.js to the asm.js -> wasm compiler.

Which with a lot of fiddling may work for the non-jitted version. But if you
want all the pypy speed you'll want to jit wasm to the browser.

I would love to know if you can do synchronous calls in wasm.

~~~
meredydd
As Albert-Jan and I discussed at PyCon this weekend, the long-term future for
Skulpt quite possibly involves compiling to WASM rather than Javascript. This
is very unlikely to happen until every modern browser supports WASM. Neither
Trinket's educational mission nor Anvil's "web apps for the world" mission are
compatible with leaving users behind just because their workplace or school
runs IE.

The runtime can be remarkably small (Skulpt is 228kb minified and gzipped,
including the standard library), so I think it's a feasible target. (Pypy.js
is, of course, enormous!)

~~~
steveklabnik
> This is very unlikely to happen until every modern browser supports WASM

WASM ships in every evergreen browser today:
[http://caniuse.com/#feat=wasm](http://caniuse.com/#feat=wasm)

Only significant browser missing it is IE; only Edge has support.

------
fulafel
Standard Python is nicer for writing clients in many cases.

------
albertjan
We're back up! :)

~~~
dpedu
The code won't run in my browser and I'm seeing Javascript errors. Hope this
helps: [https://i.imgur.com/gRLw9IW.png](https://i.imgur.com/gRLw9IW.png)

