Python, one of the world’s most popular programming languages, may soon become even more ubiquitous as it finds its way into 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 in web browsers through WebAssembly or WASM.
CPython on WASM follows a project that started in April called Pyodid which also allows Python code to run in a web browser.
“The new project Christian Heimes and I are working on is aimed at making the web a supported platform for CPython, just like Windows or macOS,” Smith explained in a note to The register.
Thanks to recent commitments from @ChristianHeimes, I found the correct incantations to create the main branch of CPython for the web!
This is the original Python that runs * in the browser *.
My scripts to build this are at https://t.co/UxhHLBupj4
A lot of work to sort things out though … 👷 pic.twitter.com/gIFlVNpNiX
– ethantyping (@ethanhs) November 26, 2021
“Hopefully this will allow for a larger ecosystem of Python developers targeting the web and allow for easier integration with existing Python tools and processes, many of which Pyodide had to reinvent as micropip to replace the standard pip package installer. Finally, I would also like to look at WASI, the WebAssembly system interface, as a way to sandbox server-side Python code. “
Pyodid, Smith said, has a narrow focus – to run scientific computing code in the browser – and therefore uses a few hacks to get the wrapper to work properly. He sees the CPython project on WASM as having broader goals.
“I don’t want this project to be as specific as Pyodid, but we really want to work with them to make sure we don’t duplicate the work and that scientific computation workloads work well with CPython on WASM,” he said. -he explains.
“The main technical difference between our project and Pyodide is that we are not building a patched version of CPython,” he said. “Instead, we’re upstreaming our fixes, which have already made cross-compilation in general a lot easier.”
The WASM method
He also said that CPython on WASM could be useful for the development of cross-platform web applications, although he acknowledges that work is already underway to bring CPython support to iOS and Android and that there is more. ‘other cross-platform projects like BeeWare.
When asked if the tie-up with WASM will make Python more competitive in terms of speed, Smith acknowledges that this could be a problem.
“Our first battle here is actually page load time, but we’ve already been able to reduce the size of the standard library to around 5% of its original size, and we can do more,” he said. -he explains.
“As for the speed at run time, I think the story will actually be the same as running on a server: if some of your code isn’t fast enough, call C, C ++ or Rust. ‘from Python shines. Rust in particular has excellent platform support for WASM and I think that would make a good pairing to speed up Python code running on WASM. “
CPython on WASM, he warned, is still in the early stages of development and the project is more ambitious than functional at the moment.
“If anyone wanted to start a project today, I would most likely recommend that they start with Pyodide, which has been around a lot longer and has more finishing,” he said. “But I look forward to working with the CPython and Pyodid developers to continue improving Python on WASM.” ®