Mozilla promotes Pyodide as independent project to put Python in a browser

Mozilla promotes Pyodide as independent project to put Python in a browser

Mozilla has spun out Pyodide as an independent community-driven project aimed at enabling Python to run in the browser to support data science workloads.

Pyodide has reached release 0.17.0, adding several new features and improvements. As it has become an independent project, Pyodide has been given a new home in a separate GitHub organisation (github.com/pyodide) and is maintained by a volunteer team of contributors.

According to the Mozilla Hacks blog, Pyodide comprises the CPython 3.8 interpreter compiled to WebAssembly which allows Python to run in the browser. A selection of popular Python scientific packages have also been compiled and made available, and Pyodide can install any Python package with a pure Python wheel from the Python Package Index (PyPi).

Pyodide 0.17.0 was hailed as a major step forward from previous versions by the project team, and includes a redesign of the central APIs, and careful elimination of error and memory leaks.

One of Pyodide’s claimed strengths is the foreign function interface between Python and Javascript, which can make it much simpler to work with two different languages. However, a major pain point until now was that if an object made a round trip from Python to Javascript and back to Python, it might come back different. This was often caused by implicit conversion of Python types to Javascript.

In Pyodide 0.17.0 , the type translations module has been significantly reworked to ensure that translation of objects between Python and Javascript produces an identical object. This applies either way round, so that Python to Javascript or Javascript to Python produces objects equal to the original object, barring a small number of exceptions due to unavoidable design tradeoffs, the Pyodide team said.

Another major new feature is the implementation of a Python event loop that schedules coroutines to run on the browser event loop. This makes it possible to use the asyncio library for concurrent programming in Pyodide.

It is also now possible to await Javascript Promises in Python and to await Python awaitables in Javascript. This allows for interoperability between asyncio in Python and Javascript, although the Pyodide team warned that memory management issues may arise from this.

Other notable changes are that errors can now be thrown in Python and caught in Javascript, or vice versa. There have also been a number of bug fixes in this release, which are listed in the Version 0.17.0 changelog.

Pyodide was originally developed by Mozilla to allow the use of Python in Iodide, an earlier effort to build an interactive scientific computing environment for the web. But while Pyodide has attracted a large amount of interest from the community, the Iodide project is being wound down.

The Pyodide project team has approved a governance process and published a roadmap for future developments. The team also welcomed new contributors participating in the project development on Github.