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

Uploaded CPython 3.8+Windows ARM64

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

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.10.5-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.5-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.5-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: pyoz-0.10.5-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.5-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 39886449f4abf75521cd096ab27b8c27f3e5c8892b65d6f53cbe7faf91201c89
MD5 1015ce60118a33be5ca77c66f47c8aaa
BLAKE2b-256 da0c2d1624ad7df67e4af736b3955d1d6c9b18d0ee7449f8c64cc51b111741be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.5-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.5-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 975db69c67ca1cc62c71434b526b3143c0bf338cecdd2c7f4d1acaf368519912
MD5 b873a5f73f402b09338f784955cf375a
BLAKE2b-256 e3ad59546eac92852a8a4a73259d4e049071cdf49a7de46fddf13e1258208251

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.5-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8428a3514d38204722a7971e500ab4c982441df9d49143820ad748581848782e
MD5 ef79377cdaa3f9e63d1c5814740e51e9
BLAKE2b-256 bd5cc3cccd0e944757b49f7e633195b499ce6b78a73e79c39947e657bb0fbd16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.5-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 025b648680bbbacddda0eae8470af2c27489c2b584f4b384939d4c31f34bd749
MD5 76351dec1adffc117af41138bca4226e
BLAKE2b-256 6ed7e3ffdf2915ec47d9da7c172c836cea2940dd969a27d9c73018d6c5094fc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.5-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b1c893fd7e9b9e141d2c7d589e3ca5584ecf3d8d868c648f2c4f2eca902250e6
MD5 034ae6eb53655220eefafcc3d029834c
BLAKE2b-256 30942739bd626c0e064f5a514a9276c208693579b8ea9f73e5b4b395306b32cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.5-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.5-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 942126a0f578d12611c72a627a20bee9b3838a8e50e8df107d528c36b99d50b9
MD5 a38f27a6a1f8c07ecfe0bc9c70c22f80
BLAKE2b-256 d357be3ab1ece74789acc7f03e92db6938e731ffe3ccdebcc96a99133bc03987

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