Python In Go - Introducing Grumpy
Written by Kay Ewbank   
Thursday, 12 January 2017

Google has developed an experimental Python runtime for Go that translates Python code to Go, then runs the code in the Go runtime.

The thinking behind this crazy sounding scheme is to find a way to make concurrent  workloads perform well. As a post on the Google open source blog by Dylan Trotter of YouTube Engineering explains:

"Google runs millions of lines of Python code. The front-end server that drives and YouTube’s APIs is primarily written in Python, and it serves millions of requests per second! YouTube’s front-end runs on CPython 2.7, so we’ve put a ton of work into improving the runtime and adapting our application to work optimally within it."

Trotter explains that while the work has been relatively successful, the problem remains that it's very difficult to make concurrent workloads perform well on CPython. Other Python runtimes all involved trade-offs, so:

"we asked ourselves a crazy question: What if we were to implement an alternative runtime optimized for real-time serving?"

The choice of Go as the platform came down to a number of benefits, including lightweight threads and first class language interoperability.

The result was Grumpy, an experimental Python runtime for Go that translates Python code into Go programs, and those transpiled programs run seamlessly within the Go runtime.




The goal is for Grumpy to be a drop-in replacement runtime for any pure Python project. There are two limitations because of the design choices made by the developers. Firstly, because there's no support for C extension modules, Grumpy can't make use of existing Python C extensions. This choice was made because it gave the developers flexibility to design an API and object representation that scales for parallel workloads.

The second limitation is that Grumpy is not an interpreter; Grumpy programs are compiled and linked just like any other Go program. This limits development and deployment flexibility, but creates opportunities to optimize performance at compile time via static program analysis. It also means that interoperability with Go code becomes both powerful and straightforward.: Grumpy programs can import Go packages just like Python modules.

A limitation that could be of more consequence to Python developers is that Grumpy runs Python 2.7 rather than Python 3. The developers at Google say this is because they have a large codebase in Python 2.7 to support. In a conversation on Github, Dylan Trotter said:

"I definitely would like to support Python 3. It's just a bunch of work. Probably requires forking grumpy and building out all the v3 features."

"Another path may be to support Python 3 features in the existing Grumpy runtime and transpiler at the risk of making things less maintainable."

Grumpy is still alpha software, but most of the language constructs and many core built-in types work like you’d expect. Trotter says that:

"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. If you find things that you wish were working, file an issue so we know what to prioritize. Or better yet, submit a pull request."



More Information


Related Articles

Go Language Of The Year With Dart Catching Up

Python 3.6.0 Beta 1

//No Comment - Python 3.6

Kivy 1.9 Released  

Python 3.5 Released



To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.



.NET 6 Preview Adds MAUI

The second preview of .NET 6 has been released with new APIs and early builds of .NET MAUI, the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, ta [ ... ]

Oh My Git! The Game

Learn how to use Git with this fun, interactive game which takes you from being a complete newbie to efficient expert by covering everything you are likely to need. 

More News






or email your comment to:

Last Updated ( Thursday, 12 January 2017 )