X
Business

Google gets Grumpy to transpile and run Python on Go

Interpreters are out and native code is in for Google's Python to Go transcompiler, which is designed to replace CPython 2.7.
Written by Chris Duckett, Contributor

Citing a lack of performance when it comes to concurrent workloads, Google decided it needed to toss out the standard Python interpreter in favour of a new approach that transcompiles Python into Go.

The new Apache-licensed project is dubbed Grumpy, and it works by taking Python source code, translating it to Go source code, and compiling it to run as native code. Grumpy is meant to be a drop-in replacement runtime for pure Python code.

"This means that Grumpy has no VM," the project states. "The compiled Go source code is a series of calls to the Grumpy runtime, a Go library serving a similar purpose to the Python C API."

Writing in a blog post, Dylan Trotter of YouTube Engineering said Grumpy programs are able to import Go packages, and use the garbage collection within Go rather than reference counting, but a design choice was made so that Grumpy cannot make use of existing Python C extensions.

"Grumpy cannot leverage the wealth of existing Python C extensions, but it gave us a lot of flexibility to design an API and object representation that scales for parallel workloads," Trotter said. "We think Grumpy has the potential to scale more gracefully than CPython for many real-world workloads.

"Although it's still alpha software, most of the language constructs and many core built-in types work like you'd expect. There are still holes to fill -- many built-in types are missing methods and attributes, built-in functions are absent, and the standard library is virtually empty."

Trotter said the project began out of a need to improve Python execution on YouTube, which runs its front end on Python 2.7, to handle concurrent workloads well.

The Go programming language was created by Robert Griesemer, Rob Pike, and Ken Thompson in 2007 for programming on Google-sized workloads, and was publicy announced in November 2009.

Editorial standards