Calling Go from Python

237 views
Skip to first unread message

Amit Lavon

unread,
Apr 6, 2021, 2:10:49 PM4/6/21
to golang-nuts

Hi,
A cheat-sheet I wrote for myself evolved into a full tutorial on calling Go directly from Python using ctypes and dll's, so I am happy to share it with the community. It starts from the very basics and covers how to handle arrays, strings and objects in both directions, memory management, performance, and even how to interact directly with numpy and pandas objects. I hope it's useful for the pythonistas among you.

Any feedback, ideas and questions are welcome.

Amit

jin jiao

unread,
Apr 6, 2021, 8:50:16 PM4/6/21
to golang-nuts
Hi Guys, I want to build a Terraform provider for our platform, so we can automate our platform tasks and API calls directly from Terraform. So both Golang and Terraform experience will be desired.More info about Terraform providers can be found here:
https://learn.hashicorp.com/tutorials/terraform/provider-setup

Justin Israel

unread,
Apr 7, 2021, 1:10:03 AM4/7/21
to golang-nuts
Nice write up! I've use the ctypes approach for a few situations and its great to have a detailed reference guide like this. 

Also recently I started using https://github.com/go-python/gopy and have been contributing a bunch of fixes and features. For simple situations though it is much easier to just use the ctypes approach since you have fine grained control over the access. As long has you don't have too much to expose to python, and too much memory management and type shimming to do.
 

Amit

Amit Lavon

unread,
Apr 7, 2021, 3:56:18 AM4/7/21
to golang-nuts
Thanks!
Gopy seemed promising back when I started exploring this topic, but I had some issues getting it to work, especially on Windows. It may have gotten better by now. Anyway I agree it's beneficial to have both approaches available so I am happy to see gopy grow as well.
Reply all
Reply to author
Forward
0 new messages