https://preview.redd.it/ziggy-pydust-a-toolkit-for-building-native-python-v0-fehgz1ui2lsb1.png?width=1797&format=png&auto=webp&s=999c288145f7ee94573dba2bac9b462d1a7ec40e
Hi all! I'd like to share Ziggy Pydust, a project that makes it easy to write Python extensions in Zig.
If you're not familiar, Zig is a low-level general purpose programming language that provides improved safety over C/C++ and powerful compile-time meta-programming called "comptime".
Pydust makes heavy use of comptime to provide a more Pythonic experience when writing native extensions, while still providing low-level access and tight integration with the CPython APIs.
pub const Math = py.class(struct { pub fn add(args: struct { x: i32, y: i32 }) i32 { return args.x + args.y; } });
One of our favourite features of Zig is the `defer` statement which allows you to register code to run at the end of the scope. This is incredibly useful for remembering to run `Py_DECREF`!
const str = try py.PyString.create("Hello, world!"); defer str.decref();
Pydust _almost_ has full coverage of the CPython Limited API, currently runs on Linux and MacOS, and is integrated with Poetry as a build system.
-
Check out the project here: https://github.com/fulcrum-so/ziggy-pydust
-
There is a GitHub template to help you get started: https://github.com/fulcrum-so/ziggy-pydust-template
-
And also a user guide: https://pydust.fulcrum.so/