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.10.3-cp38-abi3-win_arm64.whl (563.7 kB view details)

Uploaded CPython 3.8+Windows ARM64

pyoz-0.10.3-cp38-abi3-win_amd64.whl (574.6 kB view details)

Uploaded CPython 3.8+Windows x86-64

pyoz-0.10.3-cp38-abi3-manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.10.3-cp38-abi3-macosx_11_0_x86_64.whl (440.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.10.3-cp38-abi3-macosx_11_0_arm64.whl (421.8 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.10.3-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 563.7 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.10.3-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 5ae88e3a86d0fbddef00d2483f0108a02186064916c2b45347aacd99a636aa36
MD5 23de6cf2b1b2edb0752041f64611cec3
BLAKE2b-256 6d9b72a675cf60ea5afc21ef02cc31bf15c04cab1ff80e803ef932e814180613

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.3-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 574.6 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.10.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 96089845d504cc1f8eae360ef8d3926b754a317009683b1f1c783e02072fdf32
MD5 4c4e3d99ca1b58a365352c79afb44f51
BLAKE2b-256 1d532fcf6b7de32252c25e9731b964e26e13ccffdb22323a9324078058402dd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.3-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 996e1ff46e23d18a511ad6520482ec361f2755364efe2aee1023b5450d32c2e5
MD5 ab8f590fc721b51c6149827b315ef7b3
BLAKE2b-256 5472ba18c9e557094c378bbdef3b31dcfcc6e685371b463cb4224601302e4a92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.3-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5b245430e49e8717a868fc74436f5b4aa27fa78f6c1bd1bd3d076eb8549ef390
MD5 ce0e7c18cf4409f7f41b6b82b9d98464
BLAKE2b-256 4ac7e81a6df7150c73a18fbbc9e7cc18df23bc0af3dbe68495fd605d8ee8e38a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.3-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 891916fd42968a58544e91731c3ec8461458609ce92495207acd81a730f626d7
MD5 3db849ae4ee3347085b4c390d5b45efd
BLAKE2b-256 fd691cbaab4cff2adebe1e2b3dae6654a2ada1daafef45a89538116989b33cbd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.3-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 421.8 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.10.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e00572f0de0a5ac11b1128903be4c86ca0bdeaa0a5cfbc7fda311da98aaef261
MD5 52e895e6855f62420cacdac43c73ade5
BLAKE2b-256 3d9819b1f33be5dcb5dbbcef93f4f25b9c2e41a95ef7777b1fe8e3b4fce9acf4

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