Paul Krill
Editor at Large

Wasmer unveils Python to Wasm compiler

news
Apr 24, 20242 mins

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

Speed, fast, performance
Credit: 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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author