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

Uploaded CPython 3.8+Windows ARM64

pyoz-0.12.1-cp38-abi3-win_amd64.whl (602.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.12.1-cp38-abi3-macosx_11_0_x86_64.whl (470.2 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.12.1-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.1-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: pyoz-0.12.1-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.1-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 21ff7a05aa4bf6a0f7a8c3092e98c354c42b886e34ed2754bab3f1483d290566
MD5 18f6f31e840a3f242b8854845bda7472
BLAKE2b-256 5ec34ac87dc167ba1deb571ed88eb19fd5fbdd2aa4ade116b771b17fcaebdfcf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.12.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 602.4 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.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f6bde1a9c4ccef97b91b13a1da3d0c9e5b26a76bf9fb814c144d1c08460aa4f9
MD5 37ffe797517338d19a53a34c8384c7fc
BLAKE2b-256 d02a1935484bc711bdc064b698799b8474122881ca1fe6ab185b4ab0a95daa56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.1-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c524e9cbe2fd63d234b347339e7f7a95ffedf366d75824346ac2ae259c359df4
MD5 4db2db2f091d9a7dbe17b4d77260e349
BLAKE2b-256 6bdec39b5300721cb1e613561099b49d4de96fdaa1756ad20698d07d39791f35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.1-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ef5ab356916cc02f3ff537740d54b78a5c98a9ae6ea60bb8da7be8f5298d17ea
MD5 23e90dba12c1c97e86b57253a784818b
BLAKE2b-256 4f6129ef4af4573872b2042af959b155913352de129bbeab1215f820ad6bde37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.12.1-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 881c781c2d732e2932fd0c9fe325ad99b214992404c48d9d8b7d8a77645ad5fb
MD5 3ecd5d875a98b6a683822666e7451c78
BLAKE2b-256 3fd1e457848eb7da89826b2510c4cc4088a93e098857b56920309371d5cadd46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.12.1-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.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 af5b57136cac17690c5832b4f8854a88c767866c30ad74c5a04377753cc9a00b
MD5 2183be847ef13786dc0e531c02dd1080
BLAKE2b-256 e6871e6d35e249093b7f54026707a0076df49253c38939f6c36956c129f70544

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