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

Uploaded CPython 3.8+Windows ARM64

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

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.10.4-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.4-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.4-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: pyoz-0.10.4-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.4-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 48a5d9463a78d788cdbded6c3fe43da2d6a54e536f2d990242cd4c80678366f0
MD5 dde211a98b01edc7e8d7ff7e3461b91d
BLAKE2b-256 fa6ed74c57aabacabef36cc8603e7344121c490a215c668f83c77f1c91902c72

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.4-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.4-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1b8de6c91052dd7eef97b800f5f7106351b26bb635c063480adbe0fe01b0541d
MD5 e0c3e05952dec5f6f00e28d27660a70c
BLAKE2b-256 94989a76d572750048e4ad405da74c3691b597002883c51ed8d04e27fc0db5ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.4-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2bbd0ec6b03525acabd6a92b8c38288e7172532fda9ad1be918163539df007b
MD5 b22d2275bab641f0ac98c96eaff54431
BLAKE2b-256 b71560a07bc3857f1ee446d2df280e06aaf106bc51a78d424890d7c1f2c66f03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.4-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cf8b1beb4f51fc8db2e5eb00f8663517c863d42009f76d247898836045e9313c
MD5 046d01de5ae928fc38b2844356e35cd3
BLAKE2b-256 c57362d1511b5d7da25c148f63aae2a5ea1a6578abb983e803ee1c8bdb99e625

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.4-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 740b5b081b79980b707b7f267819e176180289ae3f0ad313f68c8006c7606411
MD5 2774e143fbc43ff27574af3190628d63
BLAKE2b-256 b9548399574ef9e04c5c3c61b3c6671384990a2cc24164a3241eda0c76485acd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.4-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.4-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 51de75d97dd962ae9f7b303b302106602551abd1d154dfdf75abe63f05a07768
MD5 ea2ccbf0a417980eac177be25de8cd94
BLAKE2b-256 3a10598c89b3d93e333d896156b70a87696e8784424eab89f532edb242171277

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