Skip to main content

namz (Python)

Lossless codec for NeuralAmpModeler .nam files.

A .nam is JSON whose bulk is one or more flat "weights" arrays written as ~20-character decimal strings — which the NAM engine loads into float32 anyway. .namz stores each weight as a 4-byte float32 instead: ≈5.5× smaller, bit-exact to what the engine computes, and deterministic (no compression → byte-identical across runs, platforms, and languages). A small readable header exposes tone/gear/device metadata without decoding the weights.

This package is a native Python port of the C++ reference and is byte-for-byte compatible with it and with every other port — it is validated against the shared conformance vectors (the cross-language TCK).

Install

pip install namz

Requires Python ≥ 3.9 and NumPy.

Library

import namz

nam = b'{"architecture":"WaveNet","weights":[0.5,-0.5,0.25]}'

blob = namz.pack(nam)                 # -> .namz bytes
assert namz.is_namz(blob)
assert namz.unpack(blob) == nam       # lossless to float32

# Stamp a readable metadata header (typed: "true"/"false" -> bool, digits -> int, else string;
# a leading zero keeps it a string, so an identifier such as "0012345" survives intact):
opts = namz.PackOptions(metadata={"tone_type": "hi-gain", "boost": "true", "device": "tube:1,pnp:1"})
blob = namz.pack(nam, opts)
namz.read_meta(blob)   # {'tone_type': 'hi-gain', 'boost': 'true', 'device': 'tube:1,pnp:1'} — no weight decode

API

function description
pack(nam_json, options=None) -> bytes .nam JSON (str/bytes) → .namz. b"" on invalid JSON.
unpack(data, max_json_bytes=256MiB) -> bytes .namz → .nam JSON. b"" on corruption / over-cap. Never raises.
read_meta(data) -> dict[str, str] display header without touching weights. {} for v1 / non-.namz.
is_namz(data) -> bool cheap magic check.
PackOptions(shuffle=True, metadata={}) packing options.

unpack is total: for any input bytes it returns bytes (empty on failure) and never raises.

CLI

namz encode in.nam out.namz [--no-shuffle] [--set key=value ...]
namz decode in.namz out.nam
namz map    in.namz [--json]        # print the metadata header (no weight decode)
namz verify in.nam                  # pack->unpack round-trip check + ratio

(Also available as python -m namz.)

Guarantees

  • Lossless to float32 — unpack(pack(x)) is bit-exact at any nesting depth, including -0.0, subnormals, and FLT_MAX.
  • Deterministic — pack(x) is byte-identical across runs and platforms; the codec is idempotent.
  • Robust — every malformed input (bad magic, unknown version/codec/dtype, truncation, trailing junk, a lying metaLen/numArrays, a placeholder naming no segment, an over-cap body) is rejected cleanly. Any JSON nested deeper than MAX_DEPTH (128) is refused — a .nam by pack, a skeleton by unpack, a metadata block reads as none — without the parser ever following it down; and pack refuses a .nam whose "weights" member holds an integer literal, which would read back as a placeholder.

Byte-match note

The skeleton is minified JSON with keys sorted ascending, matching the reference (nlohmann). Every double is printed with nlohmann's own digits — a port of its Grisu2 (dtoa_impl), which is neither always the shortest nor always the closest (-198.70986938476562 prints as -198.70986938476563), and of its switch between fixed and exponent form (1e+15 where repr gives 1000000000000000.0) — so the serializer is the port's own: json.dumps hard-codes float.__repr__. JSON text is read as UTF-8 only, and refused wherever nlohmann refuses it (a number past every double, an escaped lone surrogate), a value a later duplicate key replaces included. It is validated byte-for-byte against the reference: the shared vectors, and a differential run when a built reference CLI is around (NAMZ_CLI). The weight payload itself is always exact float32, never text.

  • A weight whose float32 is not finite (1e39) is refused by pack, and a payload float that is NaN or infinite by unpack, exactly as the reference refuses them.
  • An integer literal outside [int64_min, uint64_max] is a double, as nlohmann holds it.
  • Printing its own digits is slower than repr: unpack of a 15,000-float capture takes about 47 ms.

Development

pip install -e ".[test]"
pytest                      # runs the shared conformance vectors + property fuzz + adversarial suite

Versioned independently of the C++ reference; tracks wire format version 2.

License

MIT — see LICENSE. © 2026 Oleh Tsymaienko <oleh@darwinscat.com> & Alisa Lafoks <alisa@darwinscat.com> (Darwin's Cat).

Metadata

Release files for namz 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for namz 1.2.0
File Size Uploaded Provenance
namz-1.2.0.tar.gz 43.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for namz 1.2.0
File Interpreter ABI Platform
namz-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 62.0 kB

Release files / namz-1.2.0.tar.gz

Download URL namz-1.2.0.tar.gz
Size 43.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1cfedd816ff8f82f8b84b7a2b66475238eed3fd63e2ca6e154603cc1b22b9a86
BLAKE2b-256 checksum
How to use checksums
58f33bd8fdd0b055dd4ba961a42d01d032a64a7da6e6b8a01524ddebdc5dbe4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / namz-1.2.0-py3-none-any.whl

Download URL namz-1.2.0-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3bdf260981d60acc8633b0d4f3139c24197e4844156a171174883f026d72749
BLAKE2b-256 checksum
How to use checksums
f10b7964ac7b4636e629c0572ec8f514e958927c83830a46de7c271411bbc76e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for namz 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for namz-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page