1
3
Fork
You've already forked python-zig-zon
0
a native cpython extension to parse .zon files to python dictionaries
  • Zig 86.4%
  • Python 13.6%
Tobias Simetsreiter 0f63fc919a
All checks were successful
/ Build and Test (Windows) (push) Successful in 3m14s
/ Build and Test (Linux) (push) Successful in 2m26s
fix in sdist dep
2026年07月05日 17:05:39 +02:00
.forgejo/workflows switch ci to ReleaseSmall 2026年07月02日 12:55:17 +02:00
src upgrade sdist, introduce unittest 2026年07月03日 09:28:44 +02:00
.gitignore upgrade to zig 0.16.0 2026年06月21日 20:29:19 +02:00
build.zig add sdist compression 2026年07月05日 16:59:40 +02:00
build.zig.zon fix in sdist dep 2026年07月05日 17:05:39 +02:00
LICENSE update pyproject.toml 2025年12月01日 18:42:01 +01:00
pkg-info.zon add extra classifiers 2026年07月02日 08:50:05 +02:00
README.md readme 2026年07月03日 09:32:24 +02:00

Python Zig Zon Parser

A native python extension built with zig to parse zig-object-notation strings into python objects.

On PyPi it is only distributed in source, and built during install. It therefore needs to download the ziglang python package.

Depending on your OS, you may need the python development headers (e.g. python3-dev) installed.

Usage

install from source on https://pypi.org/project/zig-zon:

pip install zig-zon

running:

>>> import zig_zon
>>> parsed = zig_zon.parse('.{.allyourcode = .are_belong_to_us, .asd = 123}')
>>> print(parsed)
{'allyourcode': 'are_belong_to_us', 'asd': 123}

or, look at the test file

Supported values and their python type

  • structs -> dict
  • tuples -> list
  • integer literals -> int
  • hex literals -> int
  • float literals -> float
  • booleans -> bool
  • null -> None
  • string literals -> str
  • bare enum literals -> str
  • quoted enum literals -> str

Not supported values

  • bigint

How it works

The zig build commands produces a python source distribution archive ready for uploading to Pypi. It includes the sources of zig-python-sdist and a custom setup.py that handles the build of the cpython extension.

When you run pip install, the source distribution is downloaded, and since this source distribution depends on the ziglang python package at build time, a zig build command is used to compile the extension.

Developing

as opposed to other solutions for building cpython extensions in zig, i want to develop this using:

zig build

for linking against the local python installation zig-python-sdist runs a python script that imports the cpython headers into zig's build cache, run translate-c on the result and offers a cpython module to import in our zig code. On windows, the extension library is also linked against the python runtime static lib and renamed to a .pyd file for importing.