Create Python native extensions using Zig and Python C API!
First, create and activate a virtual environment and install dev dependencies (using UV and bash):
uv venv
source ".venv/bin/activate"
uv pip install -r "pyproject.toml" --extra "dev"
Then build a shared library file by executing:
zig build
The Python package can be now built and installed like so (using UV):
uv build
uv pip install "."
Use ZIG_INSTALLED
environment variable to specify what type of Zig compiler
to use (unset is for Python Zig module, 1 is for system-wide installed
binary). Then create and activate a virtual environment (example above). After
that, run the build shell script:
bash "build_python_library.sh"
Once the installation is complete, the test can be run as follows:
python "tests/test_zigmodule.py"
Have fun!
- Generate stubs automatically
- Build some Zig API for more convinient interaction with Python C API.