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

Uploaded CPython 3.8+Windows ARM64

pyoz-0.11.2-cp38-abi3-win_amd64.whl (593.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

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

Uploaded CPython 3.8+

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

Uploaded CPython 3.8+

pyoz-0.11.2-cp38-abi3-macosx_11_0_x86_64.whl (457.5 kB view details)

Uploaded CPython 3.8+macOS 11.0+ x86-64

pyoz-0.11.2-cp38-abi3-macosx_11_0_arm64.whl (438.2 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyoz-0.11.2-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 579.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.11.2-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 31c2467ad8f98567eab8ee6a0583bde854c22bf8853d1ab96e1be07a2f1530bc
MD5 84fc0e5ad6d222460d9717fef9f0035d
BLAKE2b-256 c6d6c3d652768fc4a5634fb5c115c9f96fce2fcbca994098f863ff15fdf333d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 593.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.11.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7865882582f17a5486a78b4ab771975036277e9181821bb7f928fcd2fc8a342d
MD5 9a0061e03470bc8f680e664fb1d73e7b
BLAKE2b-256 f12257867127cd8b98ab2f1aac08dfa1f4af6f6a96be9fc2274a6541b49e3bea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.2-cp38-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbfb4ca548ad550e573e33c46ba40479f404cb5e8ffd26a783e0908d4c2a2cdf
MD5 2b55017c6ac8f88279ece40bc10fc702
BLAKE2b-256 b896692d376f895b2f05d12e9a3e1d3b4bfad8e53dffa2160f04c24a067f667b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.2-cp38-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0753442cad0a7af2637c6e2d284f73596599524a8c3afb57cc79fa55621ad7cd
MD5 ab5fe891bb02c378b34cf29de2b72134
BLAKE2b-256 278302c72fefc5d0cabe540a80509ef819a46db92a7dd51d33f5609f7f227cb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyoz-0.11.2-cp38-abi3-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 8cee3fe2ccac90a3284e908f77e2d92371c91b8ee595327c2d68782cdafd791c
MD5 5c2cfd77f49b079b6c1ed2c05565ce1a
BLAKE2b-256 add057fab88e61d66e359758d0d6ee13158203aedf4342679dcb62e8db89e87f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoz-0.11.2-cp38-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 438.2 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.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d46b1e2699d58687aeeffa558dad0cdb31113f46d0bfecb8b2c647aeda68c9f7
MD5 89a518812086e94141d508d2033978e8
BLAKE2b-256 ada831caeb114b49842b9683a07a0eb735629b4a3b24a9d8b905ba96924fdf83

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