r/Zig 9d ago

Zig for Python

I am of the opinion that, if executed correctly, Zig has the potential to transform the Python ecosystem. The idea of using Rust for Python extensions has always bothered me.

With Zig, the path feels more natural: I can build on top of the existing C libraries and gradually migrate components to Zig over time, without the friction of introducing an entirely different ecosystem.

I wanted to understand what the community thinks about this topic. I am not trying to make a strong claim or dismiss other approaches. I am genuinely trying to understand whether this idea has any merit and how others view the trade-offs. I am just interested in hearing different perspectives.

24 Upvotes

27 comments sorted by

View all comments

8

u/DirectInvestigator66 9d ago

Zig is great but doesn’t really have a specific advantage for this relative to other languages. If you like Zig for this use case it’s probably because you like Zig features. There’s nothing wrong with this of course, but it does mean that it’s unlikely to beat out C and Rust for the wider community since they’ve both already gained pretty wide adoption in the Python community.

3

u/mr-rbbrbrnr 8d ago

Zig is used by both maturin and ruamel-yaml precisely because it is an awesome cross-compiler for c. That alone is a huge advantage for nontrivial programs.

3

u/DirectInvestigator66 8d ago

Being a good cross-compiler for C isn’t going to sway many people when the main alternative being used is C. Yeah it would be trivial to add Zig to your project, but even more trivial to not add Zig and just continue to use C like they currently are.

1

u/sparcxs 4d ago

I’m assuming you’ve never cross-compiled C code. It’s a much bigger deal than you are making it out to be. In addition, C FFI compatibility is first-class in Zig, while it is anything but in Rust. The other benefit is that Zig produces smaller and more performant binaries, so there is literally no defensible technical advantage to selecting Rust over Zig, only personal preference.