Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Patterns & tips

Module + class pattern

Attach classes to a module via .withTypes:

const py = @import("alloconda");

const Greeter = py.class("Greeter", "A tiny class", .{
    .hello = py.method(hello, .{ .self = true }),
});

pub const MODULE = py.module("_example", "Example module", .{})
    .withTypes(.{ .Greeter = Greeter });

fn hello(self: py.Object, name: []const u8) []const u8 {
    _ = self;
    return name;
}

Explicit method options

Zig 0.15 requires an explicit options struct:

.add = py.method(add, .{}),

Override module name detection

If symbol detection picks the wrong PyInit_*, pass the module explicitly:

uvx alloconda build --module _my_module

Control __init__.py

The CLI generates a re-exporting __init__.py by default. You can opt out or overwrite:

  • --no-init to skip generation
  • --force-init to overwrite an existing file