All Projects → nils-werner → python-go-cffi

nils-werner / python-go-cffi

Licence: MIT license
Python to Go bindings using CFFI

Programming Languages

python
139335 projects - #7 most used programming language
go
31211 projects - #10 most used programming language
Makefile
30231 projects

Python to Go bindings using CFFI

This project shows an example of how to interface with Go from Python using CFFI (and not #import <Python.h>).

There are two main routines implemented in Go:

  • Add two integers
  • Sum over a Go Slice of float64s

Both functions are accessed from Go, C and Python. Additionally, Python is actually passing a NumPy array to Go. The data is never copied but simply cast to C and then wrapped in a Go Slice.

Compile and install:

git clone https://github.com/nils-werner/python-go-cffi.git
pip install -e python-go-cffi

Test:

GODEBUG=cgocheck=0 python example.py

Currently, GODEBUG=cgocheck=0 is required as we are passing C arrays to Go, which is more strict in Go 1.6 and newer. Pull requests to fix this issue are welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].