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

Uploaded CPython 3.8+Windows ARM64

pyoz-0.11.1-cp38-abi3-win_amd64.whl (592.8 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.11.1-cp38-abi3-macosx_11_0_x86_64.whl (457.2 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.11.1-cp38-abi3-macosx_11_0_arm64.whl (438.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.11.1-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 579.2 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.1-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 94ef9b47582068aa4d52c49b9419e83b7915a0f36d0bac80259bba1e70107eb2
MD5 e2212f43ab540c4db2fa3d648a9414ec
BLAKE2b-256 80b142f2c48bc30fd6c387f8814e20dd3e9a0e68ec4bed231933c8cdfd22e60d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 592.8 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.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4d47533772b520e289b27a0f44119a20e501b2bb23aa062facdedee289007998
MD5 1a855d0eb76d9f347c55d72841d31b27
BLAKE2b-256 b202072d9fe93c60d66c29c55ca3fd25a41032346b26d4e41471dc7085778f3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.1-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 446bddd7dd2440f6529846ff6b0ed3382b33538e42cf9b24c02f45375fde4702
MD5 9048cdd997f3d4528abb657bd84c6607
BLAKE2b-256 4c2987d99df3af4333615940feb5d651d5a86c84ccde03fa68c0da41b8669d9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.1-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 915b72f52e795ce6ec884cd2d298c3fac37d21519b7a4af52420e8dc50ffde05
MD5 12dc7c9c8e40c23f7874afc5ea2ea2e8
BLAKE2b-256 c3abe76eadb3f2aafca25e8770a709154554efdf3648415d846bb6136dfece71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.1-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 120269388807f2af09d0eb6c79a8daa89b316ff4c50f14b8bc920ccef5e9cf5b
MD5 877d9123fdc46aab2b42c59b21380079
BLAKE2b-256 719760450675f060102298cb9976e6d866b56ce0566737164788baa02572ff76

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.1-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 438.1 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.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c718e5f4c40a2cf5d029e8bb8f636192ddeb74473602646f69adfae6c4684e06
MD5 e8e5c082a2f179c58a946bdd7461c8fa
BLAKE2b-256 f16791455193a78965e5f2b1ae5a3e24b76d606105d8e2f1cc8a2a5c8faada5f

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