Run Basic Python in the Browser with WebAssembly

In this Shortcut, I am going to take a bit of a detour from some of the other topics we have covered, which were mostly about WebAssembly features or how to engage with the platform directly inside and outside of the browser. In this Shortcut, we are still going to be using WebAssembly, but for a different kind of use case. In this scenario (and several more like it that will follow), we are going to be approaching WebAssembly as an implementation detail but are not going to interact with it directly.

For a few decades now, other than via plug-ins or additions to the browser platform, the only real language for interacting with the browser’s APIs or collecting input from the user has been JavaScript. We have discussed compiling other languages, such as C, C++, and Rust, into WebAssembly modules and have loaded those explicitly, but for Python, we are going to take a different approach.

Python is an interpreted language, like JavaScript, so it is not going to give us the same kind of ahead-of-time optimizations that the other languages I mentioned do. But it is a useful, friendly, and extremely popular language, so I think that making it available in popular environments such as the browser, Node.js, and Deno is a useful effort. We have discussed ways to do this via WASI and its various platforms, but for now we are going to pretend WebAssembly is not part of the story—it is ...

Get Run Basic Python in the Browser with WebAssembly now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.