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

Uploaded CPython 3.8+Windows ARM64

pyoz-0.10.2-cp38-abi3-win_amd64.whl (573.7 kB view details)

Uploaded CPython 3.8+Windows x86-64

pyoz-0.10.2-cp38-abi3-manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8+

pyoz-0.10.2-cp38-abi3-manylinux2014_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.8+

pyoz-0.10.2-cp38-abi3-macosx_11_0_x86_64.whl (439.2 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.10.2-cp38-abi3-macosx_11_0_arm64.whl (420.9 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.10.2-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 562.8 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.10.2-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 8c284a5f8075b90982227893477124188fad15b9e79ccabaaf151d6c65049a4b
MD5 8d606e48ea3c3febf18557bbb5cffde7
BLAKE2b-256 8b8dc320d2040aa665a9d2fc08496545da4509486a9ea83ae65537475e55aac2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 573.7 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.10.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f562761dd6d47e408291d59c35520c788059757cef0a4acb8ad94a40385f846b
MD5 fbbf0e71246f709e3e9d5f024ccab16f
BLAKE2b-256 70b1fe06870312087361898e11c4aa26a3dad5051266b832eaa627d4d9d152ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.2-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b839a6b2d02c5098fe2809700fb66fb5bc2c1a50cf3c3a15d78336176b80e6a7
MD5 96ac0c5f86253734dcaa48215d194bf5
BLAKE2b-256 b8e7b964cc39202a4e64c9b9f4e2d146f59c65b65b34a48feec50180fd9e7926

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.2-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f082c619ad1b9ac062a0e45449f204dc1c2a4b92392c541a8c07abc5a95d5323
MD5 54ea8d3f3e401f9ee4699b65e0baaaa5
BLAKE2b-256 19136b3e0cbceb7c324d9b76005855e35a4f97d0143aaba6ba8b7d0dd692e6bb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.10.2-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 f2a41539f865daf51d158cc226b7694ab9aebdc8e421262c7f13be6a793f23c8
MD5 23549f4c3c2587f06b0dbe847b087e6d
BLAKE2b-256 7247f622cc8dc4e3d8200953e9feb72e115ef1fca9dd950a00678fbb50a90290

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.10.2-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 420.9 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.10.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b4d3b4ade0d15533c7394c84d679817b7c384c751fa33af25358f8775641a3c
MD5 643d903fd34790247bd0cc8b9299adfc
BLAKE2b-256 f122bdbcaed098ef6358fdce3b1b64d972953e5eff418af3045585bde093193b

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