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

Uploaded CPython 3.8+Windows ARM64

pyoz-0.11.5-cp38-abi3-win_amd64.whl (598.2 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

pyoz-0.11.5-cp38-abi3-manylinux2014_aarch64.whl (2.2 MB view details)

Uploaded CPython 3.8+

pyoz-0.11.5-cp38-abi3-macosx_11_0_x86_64.whl (465.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.11.5-cp38-abi3-macosx_11_0_arm64.whl (444.8 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.11.5-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 582.5 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.5-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 e75a0774a7187fa0f18cb7368a3ba208758cf71bcedb467f83be3c5558b38c1f
MD5 e31132d725eba31b7625797994137706
BLAKE2b-256 2f331dc5e5c66d259bf27a528af1e2eb2c5ca11843e4eaafbdc720cae9f8305f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.5-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 598.2 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.5-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ebf626510c69e0c10069a50293ff1f3d9c3ef949440ed2a30a0c3e15510c0ffe
MD5 af2cb2a2d896528647ad5cfffa4ad950
BLAKE2b-256 579130d34863b60f9e9f18f69ce9d06164cced235651557a9c604a07b50dbe49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.5-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 899a3bad7a6ad71353557844f24308c2e67e3ca6d1fda30750e5482a85f386f8
MD5 cf09991038944985938b8550203ffa26
BLAKE2b-256 99ab4657b3d8fdec003312f17f8c30d1836bb5dab8477b17e54acbf91f61d5e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.5-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6f09b16f5e2227a03df6684a78eb33109752d482e0da124e204d1849bd919920
MD5 dad33081d5377754c7828907b371cdd8
BLAKE2b-256 098da2ed9b1f5710fe2a9f5a2966d2c3d17c32195e89473f892db88e1500584c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.5-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 0d073d9eee6f476c7fe9ace327ec9250bcca0f66082c9071c4b24756ee40f0bb
MD5 1b117e89412fcedf0df239870a14cacf
BLAKE2b-256 007b407844a9ac396a45ffd55a8d631723a1c194c003a86cd358bc06a60d30af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.5-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 444.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.11.5-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 522acffb5720c08126ed00f483c9855d83b9b807e7fbe33b8191d80fa53fd06f
MD5 96e74c4d93b83ab969927101b05ceab0
BLAKE2b-256 a8418a1e4a4d956d428abf8baa82b75fbb35c4c2b19a406068b944374dbb0145

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