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.9.0-py3-none-win_arm64.whl (270.3 kB view details)

Uploaded Python 3Windows ARM64

pyoz-0.9.0-py3-none-win_amd64.whl (275.3 kB view details)

Uploaded Python 3Windows x86-64

pyoz-0.9.0-py3-none-manylinux2014_x86_64.whl (286.8 kB view details)

Uploaded Python 3

pyoz-0.9.0-py3-none-manylinux2014_aarch64.whl (308.2 kB view details)

Uploaded Python 3

pyoz-0.9.0-py3-none-macosx_11_0_x86_64.whl (242.7 kB view details)

Uploaded Python 3macOS 11.0+ x86-64

pyoz-0.9.0-py3-none-macosx_11_0_arm64.whl (251.3 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file pyoz-0.9.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: pyoz-0.9.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 270.3 kB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyoz-0.9.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 35c1de0ab4b84d68af303badc775af9675f24571f5e7bd805ad1e346f604942a
MD5 0bec24f22ba74a2211f6e294fa2aa8b0
BLAKE2b-256 adf93f0a25aa6036db6abd18b252a7be3fc99d30012733006e089a8601e94bd5

See more details on using hashes here.

File details

Details for the file pyoz-0.9.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: pyoz-0.9.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 275.3 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyoz-0.9.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 55bea284916e1303b5f35a3affdec5c41df41c3a5609ab9289214f97d9beb777
MD5 9104a759ef7ed49696405fbbe75a964f
BLAKE2b-256 5bdd64744f8276dd22d38e9cdc690bb4fb38718a89d68526dbcab631118045c9

See more details on using hashes here.

File details

Details for the file pyoz-0.9.0-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyoz-0.9.0-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b19f80a85ff7d493f684a6b6f42bd14f54276230dd12649569a33f31c06a7b9
MD5 c26fc3aadb27246924801861e20e81db
BLAKE2b-256 1f6d42ab09f3ae7f373e8578be91a6dd58b3ca9c167379f9958645062aa31eea

See more details on using hashes here.

File details

Details for the file pyoz-0.9.0-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyoz-0.9.0-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8bddd6a2f1ba7bef0edfd8e8e5a9b203fb4fbed970ae4831cceee25d9f37addd
MD5 930812471ffdaf072c0bc55fe8a700f7
BLAKE2b-256 fe404a727dd17cb9497761318058832217b4da86dca1b9590db08c5ccadc9b81

See more details on using hashes here.

File details

Details for the file pyoz-0.9.0-py3-none-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: pyoz-0.9.0-py3-none-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 242.7 kB
  • Tags: Python 3, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyoz-0.9.0-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 554e9f3742e030148c078c259ac969006b7709571aebd1efbe212aea125be2fd
MD5 28af211f095c85645c1941e4f2aeac2c
BLAKE2b-256 4ba98905bc90420941a5ca7fe1f18cf586c6b8111fbc1bb3ccdeda5c676445ae

See more details on using hashes here.

File details

Details for the file pyoz-0.9.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pyoz-0.9.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 251.3 kB
  • Tags: Python 3, 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.9.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b26fc9476e3bca918c5f77b77725e20c4050a5e049a4dc7735e745f10e50bf64
MD5 e0ce89cf59462a26fce9a8974e58e509
BLAKE2b-256 7772fceb829822b489d0ce24f6b94c8c386d5d7d1af1c6852cce16aaf9c80aa8

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