FeaturedIT topics

Mozilla brings Python data science to the browser

Mozilla’s experimental Pyodide project is bringing a Python data science stack to the web browser, by compiling it to WebAssembly. Pyodide is a WebAssembly implementation of Python’s Numpy scientific computing library, the Pandas data analysis library, and parts of the SciPy library for math, science, and engineering. Python’s Matplotlib plotting library is incorporated as well.

Closely related to Mozilla’s Iodide project for doing data science in a browser, Pyodide can be used in a stand-alone fashion or in any context where developers want to run Python in a browser. Transparent conversion of objects is provided between JavaScript and Python, giving Python full access to web APIs. Basic data types are implicitly converted as well, while JavaScript typed arrays are converted to Python memoryviews.

The impetus behind Pyodide is that JavaScript, the language of the browser, does not have a mature suite of data science libraries. Numerical computing features such as operator overloading are missing as well. Mozilla would like to see the JavaScript data science ecosystem move forward, but bringing a mature Python scientific stack to the browser will be useful in the meantime.

Pyodide uses Emscripten to compile the standard Python interpreter, CPython, and scientific computing packages, such a NumPy, to WebAssembly binary format, which runs alongside JavaScript in the web browser. Loading Pyodide into the browser requires the following downloads:

  • The compiled Python interpreter as WebAssembly.
  • JavaScript from Emscripten that emulate system capabilities, such as a virtual file system, that the Python interpreter expects.
  • All of the files needed by the Python interpreter, including the Python standard library.

While these files can be large, the packages only have to be downloaded once, whereupon they are stored in the browser cache.

You can try out Pyodide by running a demo notebook from the Iodide website. (Requires a 50 MB download.) Instructions for building Pyodide can be found on GitHub.

Related Articles

Back to top button