Skip to main content

A pure Python, native ZON (Zig Object Notation) parser.

Project description

natizon

natizon (short for "native-ZON") is a pure Python parser for ZON (Zig Object Notation). Built on top of Lark, it provides a familiar, json-like interface for decoding ZON strings directly into Python data structures: like dictionaries, lists, strings, booleans, and numbers. It relies strictly on standard Python types, without AST wrappers and so on.

[!NOTE] natizon is slightly more lenient than the official std.zon parser. This flexibility is intentional, making it easier to consume and work with data in Python environments.

Installation

pip install natizon

or:

uv add natizon

Usage

natizon exposes a loads() function that works similarly to the standard library's json.loads().

[!TIP] Looking to parse build.zig.zon?

Check out this Python script for Parsing and validating build.zig.zon to see how to:

  • load Zig 0.16 package metadata using natizon,
  • validate fields with Pydantic,
  • and print a pretty JSON dump using Rich.
from natizon import loads

zon_data = r"""
.{
    .package_name = "network_tools",
    .version = "2.1.0",
    .supported_platforms = .{ .linux, .macos, .windows },
    .dependencies = .{
        .lib_a = .{ .url = "https://server.com/a.tar" },
        .lib_b = .{ .path = "../local_b" }
    }
}
"""

# Parses directly into standard Python dicts and lists
parsed_data = loads(zon_data)

print(parsed_data["package_name"])  # "network_tools"
print(parsed_data["supported_platforms"])  # ["linux", "macos", "windows"]

ZON to Python Type Mapping

When you pass a ZON string to natizon.loads(), the parser automatically converts ZON primitives and structures into their closest Python types.

Here's breakdown:

Primitives and Literals

ZON Type ZON Example Python Type Python Value Notes
Null null NoneType None
Boolean true, false bool True, False
Integer 42, 0x2A int 42
Float 3.14, inf, nan float 3.14 Supports ZON-specific keywords: nan and inf.
Char Literal 'a' int 97 Evaluates to the integer Unicode code point.
String "Hello" str "Hello" Handles standard escapes and Unicode \u{...}.
Multiline String \\Line 1 str "Line 1" Strips the \\ prefix and joins multiple lines with newlines.
Enum Literal .linux str "linux" Parsed simply as strings.
Quoted Identifier .@"complex-key!" str "complex-key!" Slices off the @ prefix and evaluates the string.

Structures and Containers

ZON Type ZON Example Python Type Python Value Notes
Array .{ 1, 2, 3 } list [1, 2, 3] Parses as a tuple if use_tuples=True is set.
Struct .{ .x = 1 } dict {"x": 1} Raises ValueError if duplicate field names are encountered.
Empty Container .{} dict {} Parses using Array rules if empty_mode is set to SEQUENCE.

Configuration

You can customize how natizon handles specific ZON structures:

  • use_tuples (bool, default False): If True, parses ZON arrays (e.g., .{ 1, 2, 3 }) as Python tuples instead of lists.
  • empty_mode (EmptyContainerMode, default EmptyContainerMode.DICT): Controls whether an empty container .{} becomes an empty dictionary ({}) or an empty sequence ([] / ()).
from natizon import loads, EmptyContainerMode

data = loads(".{}", use_tuples=True, empty_mode=EmptyContainerMode.SEQUENCE)
print(data)  # Output: ()

License

This project is licensed under the Apache License 2.0. See the LICENSES directory for the full license text.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

natizon-0.2.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

natizon-0.2.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file natizon-0.2.0.tar.gz.

File metadata

  • Download URL: natizon-0.2.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for natizon-0.2.0.tar.gz
Algorithm Hash digest
SHA256 83fea5caf49846e3271db31708ee06a8ee635b6d85e6192458a709381b938ea6
MD5 f087942bb422e32ed65c78587bb9d7b8
BLAKE2b-256 b3aec8db065bb409653f04c79e8a704532b3cad598b476f9c634ea33ae4064d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for natizon-0.2.0.tar.gz:

Publisher: release.yml on BratishkaErik/natizon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file natizon-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: natizon-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for natizon-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2034d7d2da3031c383df7b50085c87a532543705bfd70f6722eb05a1b1e5ae73
MD5 9004d6ada8c1e44f2de6863b4b44a29f
BLAKE2b-256 9fb9873f6872eb106423205156ed5f0b40843d1f3aec1ff63500b5d8abb7ee62

See more details on using hashes here.

Provenance

The following attestation bundles were made for natizon-0.2.0-py3-none-any.whl:

Publisher: release.yml on BratishkaErik/natizon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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