Skip to content

Native Extension ABI

Qubitium edited this page Dec 5, 2026 · 8 revisions

Native extension ABI

DataShoal ships C sources. The running CPython builds a local extension with its own headers and extension suffix. The binary entry point is PyInit__native(void), which initializes a Python module. DataShoal publishes no linkable C SDK, stable abi3 binary, or tensor-pointer ownership interface. Template capsules are private objects. Applications use the Python API. The tables below inventory the private Python-callable methods in that extension for maintainers diagnosing a codec or build.

The cache key includes the sources and interpreter/build configuration. A free-threaded build declares Py_MOD_GIL_NOT_USED. If compilation fails, DataShoal logs a warning and uses Python implementations. Keep cache binaries local to their build. JIT configuration and cache · C method table

All arguments below are positional. Byte counts and offsets use bytes. Callers supply validated sizes from the enclosing format. Returned Python objects follow Python ownership rules.

Parquet and compact metadata

Method Use and result
compact_fields(data) Parse compact Thrift fields from a buffer. Returns the field mapping and number of bytes consumed.
pack_arrays(values, text) Encode text strings or byte strings as length-prefixed Parquet BYTE_ARRAY payloads.
byte_arrays(data, count, text) Decode that many values, validating UTF-8 for text.
unpack_bits(data, width, count) Decode packed integer values using width bits per value.
encode_levels(values, width) Encode integer definition or repetition levels.
binary_levels(data, count) Decode one-bit hybrid levels to one byte per level.
dictionary_values(data, dictionary, count) Resolve a dictionary page’s encoded indices against a tuple of values and return a tuple.
split_list(values, reps, defs, depth) Flatten nested list inputs into child values, repetition levels and definition levels for writing.
split_struct(rows, levels, names) Project nullable structs to one pair of values and definition levels per field.
dense_lists(levels, names, fields) Reconstruct dense lists from repetition bytes and already decoded field columns.
list_column(reps, defs, values, names, maxima, list_level, item_level) Reconstruct nullable lists or lists of structs using tuple inputs and per-leaf definition maxima.
records(names, columns, start, count) Assemble a list of row dictionaries from the specified span of column tuples.
snappy(data, size) Decompress a raw Snappy block into exactly size bytes.
snappy_region(source, start, length, size) Decompress a span of a buffer into the specified output size.

Arrow IPC

Method Use and result
arrow_values(offsets, payload, width, text) Decode a column from immutable byte buffers and 4- or 8-byte little-endian offsets. Returns a list of strings when text is true or byte strings otherwise.

Xet codecs

Method Use and result
blake3_keyed(data, key) Compute a 32-byte keyed BLAKE3 digest using a 32-byte key.
chunk_boundary(data, start) Find the next Xet content-defined chunk boundary and return the absolute end offset.
lz4(frame, expected) Decode a supported LZ4 frame into exactly the expected byte count.

SafeTensors

Method Use and result
wire_check_header(data, tensors, rank, metadata) Preflight raw JSON header bytes against structural budgets. Returns None on success. Full archive validation follows in the Python layer.
wire_read(fd, start, size, writable, chunk=67108864, limit=1073741824) POSIX only. Read a checked regular-file range into owned bytes, or bytearray if writable is true. The caller owns the descriptor.

Native templates

Method Use and result
template_compile(source) Compile an exact str into a private program capsule. Source, node count, identifiers, and nesting are bounded.
template_render(program, context) Render a capsule against a plain dictionary and return an owned Unicode string. The renderer validates and snapshots data, and bounds allocation, work, and output.

The supported syntax and limits are documented in the template API.

Check the active interpreter

Run this diagnostic where the JIT compiler is available. The public Parquet and SafeTensors APIs automatically dispatch to the available backend.

from datashoal._jit import native

codec = native()
if codec is not None:
    payload = codec.pack_arrays(("shoal", "海"), True)
    assert list(codec.byte_arrays(payload, 2, True)) == ["shoal", "海"]
    assert len(codec.blake3_keyed(b"sample", bytes(32))) == 32
    assert codec.wire_check_header(b"{}", 1, 1, 1) is None

Clone this wiki locally