Skip to main content

Zero-copy reader for the Nexus Standard (NXS) binary format

Project description

NXS — Python

Zero-copy .nxb reader for Python 3.8+. Pure-Python implementation with an optional C extension for hot-path columnar scans.

Requirements

Python 3.8+. No pip install, no dependencies. The C extension requires a C compiler and Python headers.

Read a file

from nxs import NxsReader

buf = open("data.nxb", "rb").read()   # or mmap.mmap() for true zero-copy
reader = NxsReader(buf)

print(reader.record_count)             # instant — read from tail-index, no parse pass
obj = reader.record(42)                # O(1) seek
print(obj.get_str("username"))
print(obj.get_f64("score"))
print(obj.get_bool("active"))

Columnar scan

scores = reader.scan_f64("score")      # list of all values for one field

total = reader.sum_f64("score")
low   = reader.min_f64("score")
high  = reader.max_f64("score")
ages  = reader.sum_i64("age")

C extension (hot path)

Build once:

bash build_ext.sh

Use the same API, significantly faster for columnar work:

import _nxs

reader = _nxs.Reader(buf)
print(reader.record(42).get_str("username"))   # ~374 ns vs ~1.2 µs pure Python
total = reader.sum_f64("score")                # 3.15 ms at 1M records

Write a file

from nxs_writer import NxsSchema, NxsWriter

schema = NxsSchema(["id", "username", "score", "active"])
w = NxsWriter(schema)

w.begin_object()
w.write_i64(0, 42)
w.write_str(1, "alice")
w.write_f64(2, 9.5)
w.write_bool(3, True)
w.end_object()

data: bytes = w.finish()

# Convenience: write from a list of dicts
data2 = NxsWriter.from_records(
    ["id", "username", "score"],
    [{"id": 1, "username": "bob", "score": 8.2}]
)

Tests

python test_nxs.py       # pure-Python
python test_c_ext.py     # C extension (requires build_ext.sh first)

Benchmarks

python bench.py          # pure-Python vs json.loads
python bench_c.py        # C extension vs json.loads

Files

File Purpose
nxs.py Pure-Python reader
nxs_writer.py Pure-Python writer
_nxs.c C extension source
build_ext.sh Compiles _nxs.c_nxs.cpython-*.so

For the format specification see SPEC.md. For cross-language examples see GETTING_STARTED.md.

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

nexus_standard-1.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

nexus_standard-1.0.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file nexus_standard-1.0.1.tar.gz.

File metadata

  • Download URL: nexus_standard-1.0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for nexus_standard-1.0.1.tar.gz
Algorithm Hash digest
SHA256 23731bc56908917dcf5fa797dafa167b53c1030962082695870d1619ba041a43
MD5 5dcbcdc5a09b23a76e7b9fefdbe35b36
BLAKE2b-256 b90267c58548d8d00d9bc342c6c762cfc5cfe24d55688e545acc0b19e3bdbfaa

See more details on using hashes here.

File details

Details for the file nexus_standard-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: nexus_standard-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for nexus_standard-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 402f117d8b8eb4535e476e4b1be55af29d9e8ad9119e5bb2c75ccda47651498f
MD5 aff21e4279aabbc4dac487ca07633245
BLAKE2b-256 c67c9b35eb69854daea49b495f009bf9b8cc1a1f79e344ab05629a31ec80e50e

See more details on using hashes here.

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