Writing a Python extension in Go (Golang)

tehwalrus picture tehwalrus · Sep 16, 2012 · Viewed 21k times · Source

I currently use Cython to link C and Python, and get speedup in slow bits of python code. However, I'd like to use goroutines to implement a really slow (and very parallelizable) bit of code, but it must be callable from python. (I've already seen this question)

I'm (sort of) happy to go via C (or Cython) to set up data structures etc if necessary, but avoiding this extra layer would be good from a bug fix/avoidance point of view.

What is the simplest way to do this without having to reinvent any wheels?

Answer

Colonel Panic picture Colonel Panic · Sep 27, 2015

Update 2015: possible as of Go 1.5 https://blog.filippo.io/building-python-modules-with-go-1-5/

with Go 1.5 you can build .so objects and import them as Python modules, running Go code (instead of C) directly from Python.