PyOZ¶
Python extensions in Zig, made easy¶
Zig's power meets Python's simplicity.
Build blazing-fast extensions with zero boilerplate and zero Python C API headaches.
-
High Performance
Native Zig code compiles to optimized machine code. No GC overhead, predictable performance.
-
Type Safe
Zig's compile-time checks catch bugs before runtime. PyOZ adds Python type safety on top.
-
Simple API
Declarative module definitions. Just write Zig functions - PyOZ handles the bindings.
-
Full Python Support
Classes, magic methods, properties, NumPy arrays, enums, exceptions, and more.
Quick Example¶
const pyoz = @import("PyOZ");
fn add(a: i64, b: i64) i64 {
return a + b;
}
const MyModule = pyoz.module(.{
.name = "mymodule",
.funcs = &.{
pyoz.func("add", add, "Add two numbers"),
},
});
pub export fn PyInit_mymodule() ?*pyoz.PyObject {
return MyModule.init();
}
Comparison¶
| PyOZ | PyO3 | Cython | |
|---|---|---|---|
| Language | Zig | Rust | Python/C |
| API Style | Declarative | Macro-based | Mixed syntax |
| Build Setup | Simple | Maturin/setuptools | setuptools |
| C Library Interop | Seamless | Via unsafe/bindgen | Native |
| Compile Time | Fast | Slow | Medium |
| Cross-Compile | Built-in | Via cross/cargo | Complex |
| NumPy Support | Zero-copy | Via crate | Native |
| Async Support | No | Yes | Limited |
| Ecosystem | Growing | Mature | Mature |