PyScript, a means of running Python in the browser embedded in HTML, was previewed at the PyCon event in Salt Lake City, USA last weekend.
On Saturday, Peter Wang, CEO of data science company Anaconda, gave a keynote in which he demonstrated the new project. “This is something that many of us in the Python community have been hoping for for a long time,” noted Bojan Tunguz, a machine learning modeler at Nvidia.
PyScript depends on the existing Pyodide project, which is a port of CPython (the reference implementation of Python) to WebAssembly. Pyodide 0.20.0 was released last month with support for Python 3.10.
The existence of Pyodide means this is not the first time it has been possible to run Python in the browser but PyScript makes this easier and more natural. Linking to the PyScript css and JavaScript library files enables developers to embed Python code using the <py-script> tag, as well as offering a <py-repl> (Read, Evaluate, Print, Loop) component that enables Python to be typed in and executed dynamically.
The PyScript project was set up with governance including a mission statement of “programming for the 99%” and a steering committee, currently with just three members all of whom work for Anaconda. PyScript is open source using the Apache 2.0 license.
According to the project site, the goals include enabling Python in the browser without server-side configuration, running popular Python packages, bi-directional communication between JavaScript and Python, and visual development using “readily available curated UI components such as buttons, containers, text boxes and more.”
Python is by some measures the most popular programming language. Last year IEEE Spectrum declared it to be the “de facto platform for new technologies,” though it ranks second to JavaScript in the language rankings from analysts RedMonk.
It has a strong lead in machine learning, statistical analysis, and is a language with which to learn programming.
Making it easier to use in the browser will please not only scientists developing analytical applications but also general-purpose programmers in search of an alternative to JavaScript – though the project developers warn that it is “an extremely experimental project” and that it has only been tested on Google’s Chrome web browser.