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

Uploaded CPython 3.8+Windows ARM64

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

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.11.3-cp38-abi3-macosx_11_0_x86_64.whl (465.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.11.3-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.3-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: pyoz-0.11.3-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.3-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 4f6e9f60896c2474d13a9830c443078b852e55d51f83505cac480f30474eae58
MD5 78ff9eb8018f3528f0383544f643f92b
BLAKE2b-256 bc8400f4402c0e674e0d3c62b7025dcc63128fd202b19623bc4a3b23b59136ce

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.3-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.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c1b96e916a9ed2dbe954091dc4a20e37ff3d944ee95be9fa986d3165fc4f7378
MD5 de137b8017dbfbf7c8ffcc14a092ebb9
BLAKE2b-256 b01712fe8a3aecc181e97dc602223abee22abf5979422a66b6cf6935c1232f9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.3-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 df2e30020d88bbfac74c44715ab960c0b842ded08c12d5967c6a171347fcad7b
MD5 0b980175568f08405706f3a80b427222
BLAKE2b-256 da46f61e841c4d9eb3dc9a1b4c354e0bcfd17ac693dcffe71a949615b2175420

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.3-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 af97737b8ba5c45058d489220c11ebc2999ebfbee7e1f6d9cfc0d89633b9d2a6
MD5 cafe3c811a8685a390233457e0fb3270
BLAKE2b-256 177a2e7142523b6abbb45b5ee6ebb530b67b81226257be58eb9bcb3675a2ec49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.3-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 deb7ae588402007ec6ca27a530dc36f32038eaf2ab53fb4e9ed1791564e64746
MD5 954fd4cd4a455ed31997ba16966e9d40
BLAKE2b-256 93074b5ae2b8765b1edaf606d7b90b29e461810ee8c69153cb08a92373f5b0f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.3-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.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0f88e91993f639c8b8264fb51af762ec4d555e9f83c6b52ab962ea6dff1f079a
MD5 79d829578248898b6dcd7a87ed8ba39f
BLAKE2b-256 27850c7f10501f989d8702361e856fb25b81b08059d0ff03f2d70da8606f0fa8

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