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;
}

pub const Module = pyoz.module(.{
    .name = "mymodule",
    .funcs = &.{
        pyoz.func("add", add, "Add two numbers"),
    },
    .classes = &.{
        pyoz.class("Point", Point),
    },
});
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.2-cp38-abi3-win_arm64.whl (586.3 kB view details)

Uploaded CPython 3.8+Windows ARM64

pyoz-0.12.2-cp38-abi3-win_amd64.whl (602.2 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.12.2-cp38-abi3-macosx_11_0_x86_64.whl (470.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.12.2-cp38-abi3-macosx_11_0_arm64.whl (449.7 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.12.2-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 586.3 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.2-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 ea714dece8d6b4f81672d0c14626c10dc40c9b83e34fc7201c1606357efe4bbd
MD5 665c3c1790da7ab92f3c8db6e7e09cac
BLAKE2b-256 25c08887aebf319da8acd26a548696d809eec9cbc68563213b6b5acf22c8eff0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.12.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 602.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.12.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7ea9b76d2892f980c410c473457fd97f534c4ed7725f1c60f4a3780ec99e3ad8
MD5 1c47b6c73e1b2832ab9230f19a2466ce
BLAKE2b-256 e1cbb1cf53b49b5b3237dea32166d1bdf5a4be7b93b5fc10dcbf38dbc50a62ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.2-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b3be2201ee207ad0b6c89e5228538aa67e7c9cbf42ed19b0c25e340db105c60
MD5 d024b27b36f836d6dabd4b713bfa3f24
BLAKE2b-256 fefe54680762b2930b64b55ba3c62d6e0f98f8705d448205b7f29d9a28de8977

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.2-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 da24dde533ff984dbb7bf5fa797bbb8e57bebbb6190a4eec1c88598b2fe70061
MD5 fa9bd630fe62aa1dc7789be3ed9a2ffd
BLAKE2b-256 3f1bf958054afec45aecfa6de9f37bdc15e4212c8790b6e0c0d0de8a8554e907

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.2-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 d552fea9044b949badc2ae00c8b95aa242386fca55797c0f887384c1866b78df
MD5 6043e0af534eee39d93f6c3ff5d3b609
BLAKE2b-256 7009610361b31a09c8030f9f6e3c168b21d8d6bf63092e3de60b95fbb859cab1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.12.2-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 449.7 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.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 743227db0063ad6d8afc31fdf3eba6c819a381c4f91b1b361367a0a30db94ada
MD5 7bbab8384567264cfcea3283d4fa1368
BLAKE2b-256 cc4cc5a5e6d0dee3963cd5bb7019dc0c2f303ad2c7438fd322030c265884cb42

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