Paul Krill
Editor at Large

Mozilla brings Python data science to the browser

news
Apr 16, 20192 mins

Pyodide project uses Emscripten and WebAssembly to run Python and its data science libraries in any major browser

python
Credit: Mark Gillow

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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author