Pyzig

Automate Zig to Python bindings for Faebryk modules.

3.6k|225|Updated Dec 19, 2023
One-click install
npx skills add https://github.com/atopile/atopile --skill pyzig
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Pyzig
Source: https://github.com/atopile/atopile/tree/main/.claude/skills/pyzig
Command: npx skills add https://github.com/atopile/atopile --skill pyzig

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The Zig↔Python binding layer often requires boilerplate and careful management of wrappers and imports; Pyzig provides a coherent structure and tooling to streamline this process. Save time and reduce errors when extending Python with Zig code.

Core Features & Use Cases

  • Binding generation: Exposes Zig APIs to Python with minimal boilerplate and safe lifetimes.
  • Build-on-import and integration: Supports editable installs that compile on import and sync type stubs.
  • Ownership rules and lifecycle management: Documents and enforces ownership to prevent memory leaks or use-after-free.
  • Use Case: Add a new Zig API to Python by updating the binding layer, rebuilding, and importing it in Python tests.

Quick Start

Install dependencies, run ato dev compile, then in Python import faebryk.core.zig and test minimal binding usage.

Frequently Asked Questions about Pyzig

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create Python bindings for Zig code without writing boilerplate?

Creating Python bindings for Zig code is automated by Pyzig, which exposes Zig APIs to Python with minimal boilerplate while enforcing safe lifetimes. It handles loader glue, builds, and wrapper utilities to streamline interop.

Can I compile Zig extensions automatically when importing them in Python?

Yes, compiling Zig extensions on import is supported through Pyzig's build-on-import feature. It integrates with editable installs to compile extensions and sync type stubs automatically during the import process.

What do I need to set up a Zig and Python interop environment?

Setting up Zig and Python interop requires a Zig toolchain, a Python development environment, and build scripts. Pyzig uses these to compile extensions, generate stubs, and manage the wrapper layer for Faebryk modules.

How does Zig handle memory ownership when exposed to Python?

Memory ownership and lifecycle management in Zig Python bindings are handled by Pyzig through documented ownership rules. It enforces safe lifetimes to prevent memory leaks or use-after-free errors when extending Python with Zig code.

What is the best way to add a new Zig API to a Python test environment?

The best way to add a new Zig API to Python is by updating the binding layer in Pyzig, rebuilding the extension, and then importing it directly in Python tests to verify minimal binding usage.

Why does my editable install fail to sync type stubs for Zig modules?

Editable installs failing to sync type stubs for Zig modules often stem from missing build scripts or an incomplete Zig toolchain. Pyzig requires both to compile extensions and generate stubs during the build-on-import process.