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

Uploaded CPython 3.8+Windows ARM64

pyoz-0.12.0-cp38-abi3-win_amd64.whl (602.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.12.0-cp38-abi3-macosx_11_0_x86_64.whl (470.4 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.12.0-cp38-abi3-macosx_11_0_arm64.whl (449.8 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.12.0-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 587.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.12.0-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 a62f2b8a7ba97ecab21b1a19bf491417b9d6b2ee7604b9faaf699cc5a24d2d97
MD5 89a9132a6524e39d590cf324aea38baa
BLAKE2b-256 83ec5b6360381f3bee8ce33cae3ba154e49f38fe86472c22ca09ca0719f205cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.12.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 602.8 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.12.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f42df5e874c4344cac4a4ef2d23c883d1fd23a41a2811e03e22b7f0fdb00fd01
MD5 cca96f1c90c8cd568a1c5d96e7d03f98
BLAKE2b-256 582feaedfb1cf47ba68f163bd0711538b252fa259e027b4e68cf41100bae3611

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.0-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b581b82150cb97656ba1b0aeb81c9fab47890dbbfd3eab4a9c73793c6134c04
MD5 0ac35d65013deb0984de6d8c5e3cf434
BLAKE2b-256 35bbf946c0aff76937bafa3dfdddf8da8c7472a7060093498d550e7f357bc1b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.0-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9704be3881d6f9799fd1a00fddc52cbdab066f118fdd7e9c9b9703acba9f09df
MD5 95c623d95ee35272710db7d841fcbd0d
BLAKE2b-256 03cd0d55f75c58cbe88ee5bdeace71a64618db8d3758c406a23f81a8e0c92607

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.0-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 bf4935fc02452741fd3cfb455f5560347ebcfe15d952871bdbdf35f201fd6318
MD5 9b56125694c6837d56a36f4fa91134e5
BLAKE2b-256 2c8fded1ad5e2af40c5eb35401993f0941fe5441c632ab95d7d1f27c39974eef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.12.0-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 449.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.12.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79951edba3af8f4024106dac4aafd81dd284137a3283158634ab6786a53690e0
MD5 6fbaa35dfeead68a05b5bdaef1ea1a42
BLAKE2b-256 f8bfacd97fbc507b11643300c217d5dc45fcae8c204bf0915e5e2d7a9008a9cf

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