Skip to main content

Python extension modules in Zig, made easy

Project description

PyOZ

Zig's power meets Python's simplicity. Build blazing-fast Python extensions with zero boilerplate and zero Python C API headaches.

Documentation | Getting Started | Examples | GitHub

Quick Example

Write normal Zig code -- PyOZ handles all the Python integration automatically:

const pyoz = @import("PyOZ");

const Point = struct {
    x: f64,
    y: f64,

    pub fn magnitude(self: *const Point) f64 {
        return @sqrt(self.x * self.x + self.y * self.y);
    }
};

fn add(a: i64, b: i64) i64 {
    return a + b;
}

const MyModule = pyoz.module(.{
    .name = "mymodule",
    .funcs = &.{
        pyoz.func("add", add, "Add two numbers"),
    },
    .classes = &.{
        pyoz.class("Point", Point),
    },
});

pub export fn PyInit_mymodule() ?*pyoz.PyObject {
    return MyModule.init();
}
import mymodule

print(mymodule.add(2, 3))  # 5

p = mymodule.Point(3.0, 4.0)
print(p.magnitude())  # 5.0
print(p.x, p.y)       # 3.0 4.0

Features

  • Declarative API -- Define modules, functions, and classes with simple struct literals
  • Automatic type conversion -- Zig i64, f64, []const u8, structs, optionals, error unions all map to Python types automatically
  • Full class support -- __init__, __repr__, __add__, __iter__, __getitem__, properties, static/class methods, inheritance
  • NumPy integration -- Zero-copy array access via buffer protocol
  • Error handling -- Zig errors become Python exceptions; custom exception types supported
  • Type stubs -- Automatic .pyi generation for IDE autocomplete and type checking
  • GIL management -- Release the GIL for CPU-bound Zig code with pyoz.releaseGIL()
  • Cross-class references -- Methods can accept/return instances of other classes in the same module
  • Simple tooling -- pyoz init, pyoz build, pyoz develop, pyoz publish

Installation

pip install pyoz

Requires Zig 0.15.0+ and Python 3.8--3.13.

Getting Started

# Create a new project
pyoz init myproject
cd myproject

# Build and install for development
pyoz develop

# Test it
python -c "import myproject; print(myproject.add(1, 2))"

Documentation

Full documentation at pyoz.dev:

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyoz-0.11.0-cp38-abi3-win_arm64.whl (579.3 kB view details)

Uploaded CPython 3.8+Windows ARM64

pyoz-0.11.0-cp38-abi3-win_amd64.whl (592.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

pyoz-0.11.0-cp38-abi3-manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.8+

pyoz-0.11.0-cp38-abi3-manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.8+

pyoz-0.11.0-cp38-abi3-macosx_11_0_x86_64.whl (457.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.11.0-cp38-abi3-macosx_11_0_arm64.whl (438.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file pyoz-0.11.0-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: pyoz-0.11.0-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 579.3 kB
  • Tags: CPython 3.8+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyoz-0.11.0-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 5ae5968a14282f5c2840f2e58372b72dafcff18d0ea981c1048809abd272dbac
MD5 c503669ca0e5a2e83f72a13d08dfd099
BLAKE2b-256 638d52bc117eee39b6a21de7bb92d9e73ddbda576e6bf3c35b51b3bdc841a2d4

See more details on using hashes here.

File details

Details for the file pyoz-0.11.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: pyoz-0.11.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 592.8 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyoz-0.11.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 aa0d87872d396cb9476dde381fadfb4e1ee89ffd8ac8d10510d098a20437087e
MD5 c2006d999c066955201e44b5e6be5d53
BLAKE2b-256 164ee680a92381a618033ad3a57f93ad6653f837f7d636572aa6ff2b1170172a

See more details on using hashes here.

File details

Details for the file pyoz-0.11.0-cp38-abi3-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyoz-0.11.0-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8bfd359be248357f7aa94792aad960654f0862b8cc49e64ae44106383cd95a37
MD5 68e575affb832dfdb1477ee64ba92ae7
BLAKE2b-256 f557b2d5d3c7df6cda4dcfda4d09829b163bbe656bd248aa9b3c4b4c15c80d8b

See more details on using hashes here.

File details

Details for the file pyoz-0.11.0-cp38-abi3-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyoz-0.11.0-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1192067cda8050bb7a90ad9446805f00dd43728f9bffbcf054631d09ca137530
MD5 823a1db320f6d4888f6f30c0ebc013f3
BLAKE2b-256 79462e349989618abaa98acb9dfbdf76cccda38714a41da5d3b1c875a4362932

See more details on using hashes here.

File details

Details for the file pyoz-0.11.0-cp38-abi3-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for pyoz-0.11.0-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 618bbedbc4fe389ffeb43860d77c29f7b24cb2d36178b3ce95c9bdb491d15d57
MD5 5c5226d2d24df18499a070ab6c211abe
BLAKE2b-256 c7b5e81cd7d081acc82e8f7ec4acf6e268bc1fb03f9e3f2e6c9e9e73173bfc09

See more details on using hashes here.

File details

Details for the file pyoz-0.11.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pyoz-0.11.0-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 438.1 kB
  • Tags: CPython 3.8+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyoz-0.11.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a7161c0485b75043e2e50ed15cbb4f6b3a0fb763aff52d7727ffa650449f2954
MD5 aef1e10e14c4cdd6af7f5e0f69653979
BLAKE2b-256 b97a584b4fba6f61a10a7f916782f14a35e442b3bc1b0a5ecf3644b5a198c206

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page