# Packaging Zig as Python packages

**URL:** <https://ziggit.dev/t/packaging-zig-as-python-packages/7084>\
**Category:** Help\
**Tags:** package-management\
**Created:** [November 30, 2024, 11:35am UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084 "2024-11-30T11:35:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaeru](https://ziggit.dev/user_avatar/ziggit.dev/kaeru/32/3335_2.png) [@Kaeru](https://ziggit.dev/u/Kaeru)\
**Post date:** [November 30, 2024, 11:35am UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/1 "2024-11-30T11:35:23Z")

</div>

Rust has a fantastic tool in maturin [GitHub - PyO3/maturin: Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages](https://github.com/PyO3/maturin) in order to write libraries in Rust but provide them as Python packages.

This is being used with great success by the Ruff / uv projects [GitHub - astral-sh/ruff: An extremely fast Python linter and code formatter, written in Rust.](https://github.com/astral-sh/ruff)

It’s fantastic since this allows your library to reach out users that otherwise wouldn’t use them. Is there anything similar for zig?

Zig already provides cross-compilation to multiple targets, so for executables this seems like a simpler problem to solve as you just need to package different executables for each target you want to support (?) but for libraries the problem seeems a bit more difficult.

Does anyone know of already existing tools? Or how easy it would be to implement something similar?

Note: interesting talk [https://www.youtube.com/watch?v=O0MmmZxdct4](https://www.youtube.com/watch?v=O0MmmZxdct4)

---

<div class="post-metadata">

**Author:** ![offset](https://ziggit.dev/letter_avatar_proxy/v4/letter/o/cab0a1/32.png) [@offset](https://ziggit.dev/u/offset)\
**Post date:** [November 30, 2024, 2:21pm UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/2 "2024-11-30T14:21:00Z")

</div>

I think you’re looking for Ziggy Pydust: [Ziggy Pydust](https://pydust.fulcrum.so/latest/)

Edit: seems like it won’t work with zig 0.13 just yet, due to changes in zig

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [November 30, 2024, 3:14pm UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/3 "2024-11-30T15:14:47Z")

</div>

Zig is available on [PyPi](https://pypi.org/project/ziglang/).  
See also: [The Python Package Index Should Get Rid Of Its Training Wheels](https://kristoff.it/blog/python-training-wheels/)

---

<div class="post-metadata">

**Author:** ![Kaeru](https://ziggit.dev/user_avatar/ziggit.dev/kaeru/32/3335_2.png) [@Kaeru](https://ziggit.dev/u/Kaeru)\
**Post date:** [November 30, 2024, 10:55pm UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/4 "2024-11-30T22:55:45Z")

</div>

More information:

- Basic example of a zig project that is used by in Python [GitHub - adamserafini/zaml: 🚀 Fast YAML 1.2 parsing library for Python 3](https://github.com/adamserafini/zaml) (outdated and might not work since zig 0.9).
- [GitHub - PyO3/setuptools-rust: Setuptools plugin for Rust support](https://github.com/PyO3/setuptools-rust) setup tools for rust, used by maturin as the backed to build maturing itself, should be possible to do something similar for zig.
- Amazing but unrelated project, cargo-zigbuild was created to use zig as a linker for rust (with the objective to cross-compile rust) [GitHub - rust-cross/cargo-zigbuild: Compile Cargo project with zig as linker](https://github.com/rust-cross/cargo-zigbuild). It is also available on PyPI but through Rust’s Maturin.

---

<div class="post-metadata">

**Author:** ![Lucifer-02](https://ziggit.dev/user_avatar/ziggit.dev/lucifer-02/32/236_2.png) [@Lucifer-02](https://ziggit.dev/u/Lucifer-02)\
**Post date:** [December 1, 2024, 12:20pm UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/5 "2024-12-01T12:20:06Z")

</div>

I think you are confused here. The author mentions creating Python packages written in Zig. But the title is very confusing in terms of his intent.

---

<div class="post-metadata">

**Author:** ![Kaeru](https://ziggit.dev/user_avatar/ziggit.dev/kaeru/32/3335_2.png) [@Kaeru](https://ziggit.dev/u/Kaeru)\
**Post date:** [December 1, 2024, 1:59pm UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/6 "2024-12-01T13:59:46Z")

</div>

His comment was incredibly useful as it led me down the path of discovering cargo-zigbuild + setuptools-rust projects, which do similar things to what I want.

Also the project he linked ends up in the zig-pypi [GitHub - ziglang/zig-pypi: The Zig programming language, packaged for PyPI](https://github.com/ziglang/zig-pypi) repository which is another repository that packages a zig project into python, in this case, the whole programming language.

---

<div class="post-metadata">

**Author:** ![Anthon](https://ziggit.dev/user_avatar/ziggit.dev/anthon/32/8967_2.png) [@Anthon](https://ziggit.dev/u/Anthon)\
**Post date:** [December 16, 2025, 3:55pm UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/7 "2025-12-16T15:55:29Z")

</div>

I have been using my `setuptools-zig`for various simple extensions over the last 5 years. It is an extension for setuptools, which I recently extended to work with the `ziglang`package. So you specify the build dependency for your package to be on `setuptools-zig` (and `ziglang`) and the `.c` and `.zig` files in your sources will be compiled with `zig.`Since you can specify a specific version (`ziglang<=15.0` ), this prevents language changes to break things unintentionally.

It now also handles more complex situations, like the `ruamel.yaml.clib` ( a handful of .c files, one of which generated from Cython), on Linux ( Ubuntu and Alpine tested) and macOS. Windows still has some problems.

---

<div class="post-metadata">

**Author:** ![Kaeru](https://ziggit.dev/user_avatar/ziggit.dev/kaeru/32/3335_2.png) [@Kaeru](https://ziggit.dev/u/Kaeru)\
**Post date:** [December 16, 2025, 9:29pm UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/8 "2025-12-16T21:29:57Z")

</div>

Since I keep using this thread as a way to share useful links in relation to the question of “Zig and python, can they work together?”.

Here’s another great talk by Loris Cro, which is exactly what I wanted to find when I originally started this thread [https://youtu.be/HPmefnqirHk?si=3PuqtJJ5zlAJ60x2](https://youtu.be/HPmefnqirHk?si=3PuqtJJ5zlAJ60x2)

---

<div class="post-metadata">

**Author:** ![Anthon](https://ziggit.dev/user_avatar/ziggit.dev/anthon/32/8967_2.png) [@Anthon](https://ziggit.dev/u/Anthon)\
**Post date:** [December 17, 2025, 6:11am UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/9 "2025-12-17T06:11:27Z")

</div>

Loris actually announced that talk at SYCL while interviewing me ([https://youtu.be/Y9F5zg3tErI?list=PL5AY2Vv6EsfSgmueLbzGVJpWIw8cIFl8J&t=2816](https://youtu.be/Y9F5zg3tErI?list=PL5AY2Vv6EsfSgmueLbzGVJpWIw8cIFl8J&t=2816)), and I totally missed that (probably the nerves by being on stage), so I did not watch that video until much later.

That is a good talk, but unfortunately Loris didn’t know that if you nowadays do `python -m pip install some-non-wheeled-source-package` a wheel is made, cached and installed.

I have been working on compiling the C extension for `ruamel.yaml` with `setuptools-zig`the last couple of days. Uploading one source is however only part of the problem. Getting things to work initially and testing is still an extensive matrix (six Python versions (py39-py314) _5 OS-es (Linux, Linux-musl, macOS, Win32, Win64)_ \* 1-2 architectures ( Intel/Amd, arm, maybe more). And then it might work different on older versions of an OS, processor, etc.

I cannot test all of these combinations in the first place, so I try to get through a cross-section. And of course I ran into (link) problems in the last platform tested (Windows), because of a bug in the toolchain, and now need to recheck the workaround on the others as well ☹

---

<div class="post-metadata">

**Author:** ![adria](https://ziggit.dev/user_avatar/ziggit.dev/adria/32/605_2.png) [@adria](https://ziggit.dev/u/adria)\
**Post date:** [December 17, 2025, 6:16am UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/10 "2025-12-17T06:16:08Z")

</div>

You can also check how I am doing this in zignal

> **[zignal/bindings/python at master · bfactory-ai/zignal](https://github.com/bfactory-ai/zignal/tree/master/bindings/python)**
>
> zero-dependency image processing library. Contribute to bfactory-ai/zignal development by creating an account on GitHub.

Basically, use the raw cpython API from Zig, see which patterns repeat, and factor them out in: [zignal/bindings/python/src/py\_utils.zig at master · bfactory-ai/zignal · GitHub](https://github.com/bfactory-ai/zignal/blob/master/bindings/python/src/py_utils.zig)

---

<div class="post-metadata">

**Author:** ![Kaeru](https://ziggit.dev/user_avatar/ziggit.dev/kaeru/32/3335_2.png) [@Kaeru](https://ziggit.dev/u/Kaeru)\
**Post date:** [December 17, 2025, 8:51am UTC](https://ziggit.dev/t/packaging-zig-as-python-packages/7084/11 "2025-12-17T08:51:01Z")

</div>

This thread is all coming together now 😃

I’ll have to watch your talk too, seems very interesting and on topic. I guess keeping your code as much Zig as possible can help with some of the grandfathered issues coming from C but you will of course still have to test all different permutations.

Also thanks @adria I saw your thread of zignal yesterday and read through some of the bindings code. This is exactly what I was looking for.
