Go(lang) to Python
summary
Shows how to expose Go code as a Python extension by building a C archive with CGo + Cython, using a handle-to-pointer registry (integer IDs) to keep Go objects live, a small C wrapper layer for C++ vectors/maps, and a C function trampoline for Python callbacks. Implements object creation, methods, string and map return types, and ownership via maps. Benchmarks build 4,000 persons with ~50 friends each (4000 persons / 50 friends) and finds call overhead so high that many Python→Go accessors beat an equivalent Go-side string assembly. Code is ~130 lines Go plus CGo/C/C++ glue and minimal Cython.
AI-written summary · about
chapters (10)
- 0:00Introduction and goals
- 4:48Understanding cgo
- 7:10Architecture overview
- 9:49Wrapping a simple function
- 14:11Sharing objects and state
- 23:06Cython integration
- 30:40Complex data structures
- 35:43Error handling strategies
- 37:42Implementing callbacks
- 42:12Performance and conclusion








