Skulpt: client side Python without preprocessing
skulpt.org
skulpt.org
- 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: handles Python, turtle graphics, and pygal charting in the browser
- https://tynker.com: their Python notebook feature uses Skulpt
- http://interactivepython.org: a popular open-source textbook that has excellent Parson's problems
- http://codeskulptor.org: implements some custom Skulpt libraries that I haven't seen anywhere else
- 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.
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.
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.
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.
Plug: you could easily prototype this with Trinket embeds. Add #!/bin/python3 to the top of our Python (Skulpt) trinkets to get strict Py3 mode. Add data files via the + button (no directory support, so treat them as all in the local directory). Use the Share menu to get embed code. Paste. You've got your first interactive lesson. If your users like it, you can then decide whether and how to build skulpt in to the site.
Codingbat, Progress Graphs and Michael Jordan:
(for Java and Python - when I tried it)
https://jugad2.blogspot.in/2013/02/codingbat-progress-graphs...
Online Python Tutor looks quite interesting:
(for Python)
https://jugad2.blogspot.in/2013/03/online-python-tutor-looks...
PythonMonk - learn Python in the browser:
(for Python)
https://jugad2.blogspot.in/2013/04/pythonmonk-learn-python-i...
glot.io, an open source pastebin with runnable snippets:
(for multiple languages)
https://jugad2.blogspot.in/2017/04/glotio-open-source-pasteb...
Some of them use emscripten, IIRC.
Edit: These tools are good for beginners to learn the basics of the language. For more complete learning, I still think the traditional method of using the command line tools such as the interpreter and a text editor, and an IDE, are useful and recommended. Interaction with the real OS is a part of the learning of any (at least industrial) programming language (maybe there are some specialized exceptions) - i.e. things such as files, databases, directories, users, processes, peripherals, etc. - and not much of that can be done in the browser-only environment that these tools have.
In fact, since I am a trainer too, I sometimes come across some of my students who do not know the basics of dealing with an operating system, even as a user. E.g. some of them can only use the PC via the GUI (e.g. in Windows) and are not familiar with the command line and its commands, or even with concepts such as drives, pathnames, filenames, absolute vs. relative paths, how to reference a file in dir B from dir A, etc. In such cases I always show them some of the basics of that stuff and give them references for further learning. And I tell them that if they do not learn that stuff (or look down on it, as a few of them tend to do), it is like knowing how to drive a car (programming) but not knowing how to walk from your house to the car and from the car to the shop - in other words, you are not fully capable to even use a car due to that :)
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
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!
Anvil: full stack web apps built only with Python | https://news.ycombinator.com/item?id=15584124 (Oct 2017, 195 comments) reply
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:
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
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.
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/
Archive link: http://archive.is/leOnD
GitHub: https://github.com/skulpt/skulpt
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 ;) )
But it doesn't understand any of the new syntax added by python3 yet.
But in Skulpt the strings don't quite work like any of the Python versions.
Python 2 has a combined str/bytes type and a separate Unicode string type:
>>> type("hello") is type(u"你好")
False
>>> len(u"你好")
2
>>> len("你好")
6
...whereas in Python 3 the str type is Unicode and the "bytes" type is a completely separate thing: >>> type("hello") is type(u"你好")
True
>>> len(u"你好")
2
>>> len("你好")
2
Skulpt actually seems to work more like Python 3, except that 1) there is no way at all to work with bytes (that I can find), e.g. no encode/decode methods, and it 2) requires the "u" prefix if literals contain non-ASCII characters, even though the type of the resulting string is the same as without the prefix: >>> type("hello") is type(u"你好")
True
>>> len(u"你好")
2
>>> len("你好")
SyntaxError: invalid string (possibly contains a unicode character) on line 1EDIT: 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.
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.
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!)
WASM ships in every evergreen browser today: http://caniuse.com/#feat=wasm
Only significant browser missing it is IE; only Edge has support.