r/Zig • • 1h ago

Thought experiment: ZPython — a Python 3+ interpreter written mainly in Zig, with first-class Zig/C interop

Hello r/Zig,

I’d like to put a design hypothesis up for scrutiny rather than announce a product. The idea is a future Python implementation called ZPython: a Python 3+ interpreter written primarily in Zig, with deliberate differences where they buy clarity, performance, or better native interoperability.

The core premise is not “rewrite Python for fun,” but to explore whether Zig is a good implementation substrate for a dynamic language runtime. Zig offers explicit allocators, strong C ABI interop, comptime, predictable control flow, and a relatively small runtime surface. Those are attractive properties for an interpreter that needs to be fast, embeddable, and honest about memory and native boundaries.

Rough goals:

· Python 3+ compatibility where practical. The language should remain recognizable. Deviations should be documented as ZPython-specific behavior, not silent incompatibilities.

· Performance as a design constraint, not a late optimization. A focused interpreter loop, efficient object representation, and careful allocation strategy. I would not promise a JIT initially; the first target is a solid, fast interpreter with room for later specialization.

· First-class Zig and C interoperability. C ABI as a stable boundary, a documented subset of the CPython C API, and a native Zig extension SDK with low-friction wrappers. Native calls should feel like a designed part of the runtime, not an escape hatch.

· Explicit boundaries. Clear rules for ownership, error propagation, and memory across Python/Zig/C calls. The goal is not to make native code “feel dynamic,” but to make the boundary predictable.

· A documented concurrency and memory model. I would avoid assuming the GIL as a universal design axiom, but compatibility still matters. Any threading model should be explicit and tested, not implied.

· Staged standard library coverage. Full CPython stdlib parity is a massive undertaking. A realistic path is a strong core plus a compatibility layer, with gaps tracked openly.

The main trade-off is obvious: Python’s ecosystem is enormous, and compatibility is a moving target. A new interpreter can win on performance and native interop, but it loses immediately if common libraries, packaging, and C extensions do not work. So the interesting question is not “can it be faster?” — it probably can in narrow cases — but “which compatibility surface is non-negotiable, and where are deviations actually acceptable?”

I’m curious how this community would critique the idea. Specifically:

  1. Would a Zig-based Python runtime be meaningfully better than improving CPython’s internals or using existing alternative runtimes?
  2. How much CPython C API compatibility is required before the project is useful?
  3. Is a first-class Zig extension SDK a real advantage, or just a niche convenience?
  4. Where should a project like this draw the line between Python compatibility and runtime clarity?

I’m not claiming this is easy or imminent. I’m interested in the design space and the failure modes. Serious critiques are welcome.

0 Upvotes

1 comment sorted by

2

u/text_garden 1h ago

Fu-huck o-hoff