Based on Iodide, we now have Pyodide which allows a Python interpreter to run inside the browser and create living documents there, thus bringing data science to the browser.
As we’ve seen in “Run VSCode in the browser“, portability is the new trend sought after. And with that we mean the ease of running everything inside the ubiquitous browser, be it an IDE, a game or an interpreter.
In the case of Pyodide it was a Python interpreter which was followed quickly with support for Numpy, Pandas and Matplotlib, by far the most used modules in the Python science ecosystem, and later on with support for Scipy and scikit-learn.So not just Python but Python+Scientific stack.
from js import document
and then start calling methods on it from Python:
In this example we’re making UI widgets:
from js import iodide
button = iodide.output.element('button')
button.textContent = "Click me!"
count = 0
if elt.style.backgroundColor == 'rgb(255, 255, 255)':
elt.style.backgroundColor = '#ffcccc'
elt.innerText = "I've been changed " + str(count) +
elt.style.backgroundColor = '#ffffff'
elt.innerText = "I've been changed " + str(count) + " times!"
count += 1
While Pyodide is based on Iodide, it may be used standalone in any context where you want to run Python inside a web browser. Iodide, however, forms the basis of a tool with which you can create living documents in the browser comprising of your code, plots, data tables, even interactive visualizations into one document, running your code and witness its results exclusively inside the browser.Furthermore you can export and share your notebook so that others can easily access the source and replicate and extend your presentation.
Their repos on Github with their installation instructions can be found at project Iodide and project Pyiodide while there’s also an interactive playground at A Brief Tour of Pyiodide where you can do your experiments and experience how it works without having to install anything.
There you have it;Python after Data Science conquers the Browser too.
- A Brief Tour of Pyiodide
- Mozilla Hacks: Pyodide- Bringing the scientific Python stack to the browser
Credit: Nikos Vaggalis (i-programmer.info)