You loved running JavaScript in your web browser. Now, get ready for Python scripting – The Register

Npressfetimg 7075.png

Python, one of the world’s most popular programming languages, may soon become even more ubiquitous as it finds a home within web browsers.

Ethan Smith, a Berkeley-based software developer, recently revealed a project that allows CPython, the default implementation of the Python programming language, to run within web browsers via WebAssembly, or WASM.

WASM is a binary format that provides near-native performance within web browsers. It’s a compilation target for languages like C/C++, C# and Rust. It’s commonly used to create performance-sensitive code that JavaScript isn’t well-suited to handle; wedding Python to WASM though its Emscripten compiler is more about ease of use and distribution than performance, at least at this point.

The project, created with the help of core Python developer Christian Heimes, could make Python a viable alternative to JavaScript for some web applications and could mitigate one of the lingering pain points of Python development: the installation, dependency, and virtual environment management woes memorialized in this XKCD comic that still bedevil inexperienced developers.

CPython on WASM follows in the wake of a project that debuted in April called Pyodide that similarly allows Python code to run within a web browser.

“The new project which Christian Heimes and I are working on has a goal of making the web a supported platform for CPython, just like Windows or macOS,” explained Smith in a note to The Register.

“My hope is that this will enable a wider ecosystem of Python developers targeting the web, and allow for easier integration with existing Python tools and processes, many of which Pyodide has had to reinvent like micropip to replace the standard pip package installer. Eventually, I’d also like to look at WASI, the WebAssembly System Interface, as a means of sandboxing Python code server-side.”

Pyodide, said Smith, has a narrow focus – running scientific computing code in the browser – and thus uses a few hacks to make packaging work properly. He sees the CPython on WASM project as having broader goals.

“I don’t want this project to be quite as specific as Pyodide, but we definitely want to work with them to ensure we don’t duplicate work and that scientific computing workloads work well with CPython on WASM,” he explained.

“The main technical difference between our project and Pyodide is that we don’t build a patched version of CPython,” he said. “Instead we are upstreaming our patches, which have already made cross compiling in general much easier.”

The WASM way

One of the limitations with WASM is that it doesn’t support blocking/synchronous I/O operations, in order to accommodate JavaScript’s non-blocking/asynchronous event loop architecture. However, Smith says, “I have plans to investigate allowing synchronous I/O to yield to the browser event loop, which as far as I know, Pyodide does not currently do. This would allow for easier integration with existing code.”

Those wishing to run Python code in the browser will not immediately get access to the browser’s …….

Source: https://www.theregister.com/2021/11/30/python_web_wasm/


Leave a Reply

Your email address will not be published. Required fields are marked *