Skip to main content

Comparison

There are several ways to get Python behaviour into a Go program. The right choice depends on what you value: parity, performance, embedability, or operational simplicity.

gopy vs CPython via os/exec

The default move: shell out to python3 and parse its output.

Aspectos/exec to CPythongopy
Behavioural parityPerfect (it is CPython)Tracking 3.14, parity bugs do happen
PerformanceFast per-instruction, slow startupSlow per-instruction, fast startup
DeploymentNeeds a Python install on the hostStatic Go binary
Sandbox controlWhatever CPython gives youA Go-side globals dict you own
State between callsLost between processesHeld in state.Thread and globals
Failure modeSubprocess errors, parse stdoutGo error returns

Pick os/exec if you already require CPython on the host and you mostly batch large jobs. Pick gopy if you want the Python behaviour inside the same process with no extra runtime.

gopy vs cgo + libpython

Embed CPython via cgo, link against libpython3.14.so, and call the C API.

Aspectcgo + libpythongopy
Behavioural parityPerfectTracking, with bugs
BuildNeeds CPython headers + linkergo build
Cross-compilePainful (per-target Python)Easy (pure Go)
GIL handlingManual PyGILState_EnsureA state.Thread per goroutine
Memory modelTwo GCs side by side (Go and CPy)One Go GC over Go-allocated objects
API surfaceC API, error-proneTyped Go API

cgo wins on parity. gopy wins on every other deployment axis. If your team has the C-API expertise and you cannot tolerate parity bugs, cgo is the better choice today.

gopy vs go-python/gpython

gpython is a Python implementation in pure Go, also free of cgo.

Aspectgpythongopy
Python target3.4 surface, no specializer3.14, PEP 659 / 657 / 669 implemented
ApproachIndependent reimplementationFunction-by-function port of CPython
Standard librarySmall set~50 modules registered
PerformanceSimilar order of magnitudeTier-2 trace path adds headroom

gpython has been around longer and is stable. gopy is younger, but its target (3.14 byte-equivalent) is more ambitious.

gopy vs grumpy

grumpy is Google's Python-to-Go transpiler. The project is archived.

The compile model differs fundamentally: grumpy emits Go source that you build, while gopy interprets Python at runtime. Grumpy was tied to Python 2.7 and is not a candidate for new work.

gopy vs RustPython

RustPython is the closest equivalent in spirit, in Rust. Mature, embeds in WASM, and also tracks CPython behaviourally.

AspectRustPythongopy
Host languageRustGo
Python target3.133.14
WASMFirst-classNot a target today
MaturityYears aheadActive development

If your host is Rust, RustPython is the obvious choice. The projects compare notes on parity strategy.

Choosing between them

A rough decision tree:

  • You need exact CPython behaviour and the host has CPython: shell out, or use cgo + libpython.
  • You ship a static binary, latency matters more than throughput, and your Python is bounded in scope: gopy.
  • You ship a static binary and you are okay with a smaller Python surface: gpython.
  • Your host is Rust: RustPython.
  • You need WASM: RustPython today; gopy compiles to WASM but the embedding ergonomics are not a project goal yet.

Reference