Wasmer unveils Python to Wasm compiler

py2wasm draws on Nuitka to convert Python programs to WebAssembly and run them at 3x faster speeds, Wasmer says.

Speed, fast, performance
Ollyy/Shutterstock

WebAssembly runtime maker Wasmer has unveiled py2wasm, a Python-to-WebAssembly compiler that transforms Python programs to the WebAssembly (aka Wasm) binary instruction format.

Using a fork of the Nuitka Python compiler, py2wasm converts Python programs to Wasm, allowing them to run without interpreter overhead. Introduced April 18, py2wasm addresses a situation in which the performance of Python programs in WebAssembly has been less than ideal, Wasmer founder and CEO Syrus Akbary wrote in a blog post. Akbary said that py2wasm gets about 70% of native Python speed, and is about 2.5x to 3x faster than the Python interpreter.

Wasmer used Nuitka to speed up Python in WebAssembly because most of the hard work was already done to transpile Python code into underlying CPython interpreter calls. Nuitka works by transpiling a program’s Python calls into C, using inner CPython API calls, Akbary said. Nuitka supports most Python programs, and also can work as a code obfuscator, preventing anyone from decompiling a program.

Because Nuitka does not yet work with Python 3.12, Wasmer had to recompile Python to Python 3.11 to WASI (WebAssembly Systems Interface) and use the generated libpython.a archive. Nuitka then could use this library when targeting WASI and WebAssembly to build the executable. Because the Nuitka transpiler executed in a 64-bit architecture but generated code was running in a 32-bit architecture, work had to be done to fix the prototype, Akbary said.

InfoWorld Senior Writer Serdar Yegulalp contributed to this report.

Copyright © 2024 IDG Communications, Inc.