Python Interpreter in Browser

Introduction

Sometimes, I would just like to test a small Python code snippet interactively possibly from any device, such as a new laptop and a cell phone. Even if the device has installed a local Python interpreter, the typing, copying, and pasting experiences there are not good. IPython and Jupyter Notebook provide much better interactive experiences. But they would have to be installed separately and sometimes I don’t want to install too many things on my device.

There are many websites which host Python interactive development servers for users to use for free, such as Replit and OnlineGDB. They not only support Python, but also a rich number of other programming languages. Recently, I also realized that there are Python local interpreters in browser, such as Skulpt. They translate Python code and libraries to JavaScript and can run Python in Browser using the local compute resources. These browser development environments enabled us to share code more interactively with other people.

Repl Remote

Repl allows the user to create public repl for free, just like GitHub. It also allows the user to import projects from GitHub. Once a public repl is created, we could share the code, not limited to Python, in on website by embedding iframe to HTML.

For example, I am sharing my Hello-Underworld Python project from Repl using the following iframe code.

1
<iframe frameborder="0" width="100%" height="500px" src="https://replit.com/@LeiMao/Hello-Underworld?lite=true"></iframe>

The code will be run on the Repl server remotely. What’s more interesting is that Repl allows the user to install PyPI packages from shell.

Skulpt Local

Creating and sharing Python code using Skulpt can be as easy as writing code on Trinket, getting its sharing iframe code, and put the code in HTML.

For example, I am sharing my Hello-Underworld Python project from Trinket using the following iframe code.

1
<iframe src="https://trinket.io/embed/python/28e4aeb82c" width="100%" height="356" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen></iframe>

It should be noted that Skulpt only supports Python 2 and the Python libraries it supports is very limited because the developers will have to translate the library into JavaScript. Because of these, Skulpt has become less attractive these days.

In addition, Trinket also supports creating and sharing Python 3 code. However, because Skulpt does not support Python 3, the Python 3 code will be remotely run on their server, making Trinket Python 3 merely no different from Repl and other similar websites.

References

Author

Lei Mao

Posted on

10-26-2022

Updated on

10-26-2022

Licensed under


Comments