Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a Python extension in Go (Golang)

Tags:

python

c

go

cython

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?

like image 872
tehwalrus Avatar asked Sep 15 '12 23:09

tehwalrus


1 Answers

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.

See also https://github.com/go-python/gopy

gopy generates a CPython extension module from a go package.

like image 167
Colonel Panic Avatar answered Sep 30 '22 19:09

Colonel Panic