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

Uploaded CPython 3.8+Windows ARM64

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

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.11.4-cp38-abi3-macosx_11_0_x86_64.whl (465.0 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.11.4-cp38-abi3-macosx_11_0_arm64.whl (444.7 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.11.4-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.4-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1f6c63e77ab710044c6e89dd2b8ba56d95aa3ee95fbca1f252010635bab525b4
MD5 e1283a209c2692d2ff240608151520d9
BLAKE2b-256 536fb9b122565c7560a3a973765c4fbabc7fe9787c8c063c28268acfe0ca39a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.4-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.4-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8977da9a5a27a812853888e07589b4022850d7eaba29addb5e374df09ecb7780
MD5 920f313ac3328b8560ade851df74a83f
BLAKE2b-256 07dcf34664d944bd994a2f1f3a419eaf1bd17d28203bb441e83f431678bb03c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.4-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f44f3103b85a21c6e83df03986c6ca66a2d339ec1ff675b9a1d4c14bff30d733
MD5 c1c2a78c9830a5da9dbef561d9de1b89
BLAKE2b-256 15c995f42b3ad8613afc5cf9e77d722a3b0e214b61cb49cbda4cadde5764d1b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.4-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1241a4e4c182cef3790316fe78556e3313d2d637205b2b90a8c4c6ff1bf27c6b
MD5 059190ea7383a584952f6254658f4c2e
BLAKE2b-256 7dad03161babb0d461a9a976893105dbf5c3e50b90e9fa1174f9b4d365bc2fdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.4-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f4e95ab3eb850e6ecbaeeb0b1007e137dca729723caabc2284544e883fc42d89
MD5 f028d5f02aabd650394b939e91d34aa9
BLAKE2b-256 822c05eca542113d0e735e3fd46a786618e0993181db9ba682e9c5b860ccf742

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.4-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 444.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.11.4-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 496a63375e9538b3abe2925cedad304fe0be4522f3e567f6d1d4f0a876c5d1a0
MD5 62ecea4971182440044e9ece4e59af41
BLAKE2b-256 44c0b2b245231aff8dc5bd5dd483e5d50cbc9a276f3a0b045dce1a4b052fd30e

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