Skip to main content

DataShoal

DataShoal is a fast, lightweight data ingestion and processing library for LLM modeling and quantization. It provides reusable building blocks for streaming calibration data, reading and writing checkpoint weights, moving model artifacts, and generating source from templates. Its only Python dependency is LogBar, a logging library with zero dependencies of its own. Local and cached reads work offline by default. LogBar

Documentation wiki · Python API · Native ABI · Quickstart

Supported data and formats

Data Inputs and formats What you can do
Text and structured records Plain text, JSON, JSONL, CSV, Python row iterables, or ordered shards. Text formats also support gzip and, on Python 3.14+, Zstandard. Stream, sample, filter, transform, and batch rows. Preserve nested chat messages, token IDs, and attention masks.
Columnar datasets Parquet and supported uncompressed Arrow IPC streams, including compatible Hugging Face dataset shards. Parquet supports booleans, integers, floats, strings, binary values, lists, and structs. Project columns, stream Python rows, sample Arrow rows, read flat numeric Parquet buffers, and write Parquet.
Model weights SafeTensors files, in-memory archives, and sharded checkpoint indexes. Validate metadata, read selected weights or byte ranges, stream tensor data, and write archives. PyTorch tensor and shard-index operations are optional.
Model and dataset artifacts Local paths, Hugging Face and ModelScope caches and repositories. Resolve cached files and snapshots, opt in to downloads, or upload to Hugging Face through native Xet support.
Source and plain-text templates A Jinja2-compatible subset and plain Python dictionaries, lists, tuples, and scalar values. Compile once and render repeatedly with the C11 engine or its Python fallback. See native templates.

DataShoal supports free-threaded CPython. Independent readers and renders can run concurrently with the GIL disabled.

Install

DataShoal needs Python 3.11 or newer. We recommend installing and running DataShoal with CPython, matching development headers, and a C11 compiler on PATH. DataShoal builds and caches its bundled C11 extension on first use of an accelerated feature. Compilation can substantially speed up data processing and template rendering. If CPython, its headers, or a working compiler is unavailable, DataShoal automatically uses slower Python implementations and logs the reason once per process.

With pip from PyPI:

pip install datashoal

With uv from PyPI:

uv pip install datashoal
# or add it to a uv project
uv add datashoal

From source:

git clone https://github.com/ModelCloud/DataShoal.git
cd DataShoal
pip install .        # or: uv pip install .

Usage

1. Preview a local dataset

Given a local JSONL file with one record per line, read its first three rows:

from datashoal import load

rows = load("train.jsonl", type="dataset")
print(rows.take(3))

2. Write and read a SafeTensors checkpoint

Save two weights from a Python buffer, then read them back. PyTorch is optional.

from struct import pack, unpack
from datashoal import SafeTensors as st

scale = st.wire.TensorData("F32", (2,), pack("<2f", 1.25, 2.5))
st.save("example.safetensors", {"scale": scale})

with st.load("example.safetensors") as archive:
    assert archive.wire.tensors["scale"].shape == (2,)
    assert unpack("<2f", archive.read("scale")) == (1.25, 2.5)

For large weights, iterate over archive.chunks("scale"). With PyTorch installed, archive.torch("scale") returns a writable tensor. SafeTensors guide

3. Sample across several shards

Read your training files in a stable order. Filter out blank text, then select up to 128 examples with a repeatable seed. Sampling scans every shard and keeps only the selected rows in memory.

from pathlib import Path
from datashoal import load

shards = sorted(Path("calibration").glob("train-*.jsonl.gz"))
train = load(shards, type="dataset").filter(lambda row: row["text"].strip())
calibration_rows = train.sample(128, seed=42)

4. Fetch once and process offline

Pin a public calibration dataset to a specific revision. Run the first call on a connected machine to populate its cache. Later runs using that cache can omit download permission entirely.

from datashoal import load

repo = "neuralmagic/calibration"
shard = dict(type="dataset", file="llm.parquet",
             revision="fb6bc2f8c66543876fb31613f5872b9030220e15")
load(repo, **shard, download=True)

calibration_rows = load(repo, **shard).sample(128, seed=42)

For checkpoints, load("org/model", type="model") returns a cached snapshot directory. Add file="config.json" to get one file, or provider="modelscope" to select ModelScope. See the wiki for loading options, Hub uploads and HF compatibility.

Native templates

datashoal.templates.Template implements a bounded, data-only subset of Jinja2 syntax for generating source and plain text. It supports {{ name }}, dotted dictionary lookups, if with optional not, for over lists and tuples, else, loop counters, comments, and ASCII whitespace trimming with -. It uses strict lookups and accepts plain dictionaries with string keys, lists, tuples, strings, signed 64-bit integers, floats, booleans, and None.

from datashoal.templates import Template

template = Template(
    "{% for kernel in kernels %}"
    "void {{ kernel.name }}();"
    "{% if not loop.last %}\n{% endif %}"
    "{% endfor %}"
)
assert template.render(kernels=[{"name": "pack"}, {"name": "unpack"}]) == "void pack();\nvoid unpack();"

The C11 and Python implementations support the same subset. The subset excludes macros, filters, assignment, arithmetic, function calls, object attributes, file includes, template inheritance, and HTML autoescaping. Rendering copies and validates the input data, enforces limits on source size, nesting, work, and output, and inserts scalar text verbatim. Each template is limited to 1 MiB of source and 16 MiB of rendered output. Use caller-controlled templates and validate values for the destination language when generating source or HTML. Template API and limits

Size and speed

The full DataShoal implementation is 6,987 nonblank source lines with one Python dependency, LogBar. Its template engine accounts for 926 lines, including both backends and the Python API. On the workloads below, DataShoal rendered source 2.5× as fast as Jinja2, read owned weight bytes 2.7× as fast as SafeTensors, and collected Parquet chat rows 1.18× as fast as PyArrow and 1.17× as fast as cached HF Datasets.

Workload Reference implementation DataShoal LOC Reference LOC LOC factor DataShoal time Reference time Speed factor
Collect 10,000 Parquet chat rows as Python dictionaries PyArrow 26.0.1 6,987 72,760 0.10× 26.87 ms 31.65 ms 1.18×
Collect the same rows from a Parquet stream HF Datasets 5.2.0, streaming 6,987 43,311 0.16× 26.87 ms 73.90 ms 2.75×
Collect the same rows using a prepared Arrow cache HF Datasets 5.2.0, cached 6,987 43,311 0.16× 26.87 ms 31.37 ms 1.17×
Read 250,000 Parquet IDs into a contiguous NumPy array PyArrow 26.0.1 + NumPy 6,987 72,760 0.10× 1.82 ms 4.31 ms 2.37×
Read 64 MiB of I32 weights into owned bytes SafeTensors 0.8.0, NumPy binding 1,410† 4,792† 0.29× 8.34 ms 22.79 ms 2.73×
Write 64 MiB of I32 weights to tmpfs SafeTensors 0.8.0, NumPy binding 1,410† 4,792† 0.29× 39.18 ms 39.22 ms 1.00×
Write 64 MiB of I32 weights to a disk-backed directory SafeTensors 0.8.0, NumPy binding 1,410† 4,792† 0.29× 110.46 ms 110.51 ms 1.00×
Render 810 CUDA declarations from a warm template Jinja2 3.1.6 926‡ 11,692‡ 0.08× 1.17 ms 2.96 ms 2.53×

Times are warm medians on an NVIDIA GB10 host with Linux arm64 and CPython 3.12.14. LOC factor is DataShoal LOC divided by reference LOC. Below 1× means DataShoal uses fewer lines. Speed factor is reference time divided by DataShoal time. Above 1× means DataShoal runs faster. The Parquet and SafeTensors comparisons use 31 rounds. The template benchmark uses 101 renders. Each comparison checks equivalent output. Writes use the same source array and finish without a durable flush. Both SafeTensors write comparisons are effectively tied.

The PyArrow and HF Datasets rows use DataShoal's full package count. PyArrow's 72,760 lines cover the Python, Cython, and C++ binding sources in its source distribution. HF Datasets' 43,311 lines cover its Python package. These figures describe package footprint across different feature sets. Benchmark methods and reproduction

† The SafeTensors rows use checkpoint-specific source LOC. DataShoal's 1,410 lines cover its archive code, native I/O, wire layout, and tensor adapters. The reference's 4,792 lines cover its production Rust core and native Python binding, package initializer, and NumPy and PyTorch adapters. The full SafeTensors package, including its other Python adapters, has 5,363 production LOC. Counted files and method

‡ The template row counts DataShoal's C11 and Python implementations of the supported subset and the public wrapper. Jinja2's source count covers its full Python package. For the same template, the DataShoal C11 backend took 1.17 ms and the Python fallback took 10.96 ms, a 9.37× speedup with compilation.

Parquet benchmarks

Each cell shows elapsed time / peak process memory for the same Python chat records. Lower is better for both. Streaming consumed 1,024 rows at a time.

Rows Mode DataShoal PyArrow HF Datasets
10,000 Collect 7.55 ms / 92 MiB 9.24 ms / 257 MiB 9.29 ms / 187 MiB
10,000 Stream 7.66 ms / 75 MiB 11.72 ms / 119 MiB 9.83 ms / 203 MiB
100,000 Collect 90.97 ms / 433 MiB 92.91 ms / 1,065 MiB 88.98 ms / 723 MiB
100,000 Stream 70.81 ms / 95 MiB 117.81 ms / 240 MiB 72.44 ms / 343 MiB

DataShoal used the least memory in all four cases. HF Datasets reopened a prepared local cache for collection. The 100,000-row fixture repeats the smaller chat corpus ten times. Each library ran in separate processes on an Apple M5 Ultra. Benchmark methods and reproduction

Parquet projection, numeric reads and writes

Median elapsed time across 51 warm runs on an Apple M5 Ultra. Lower is faster. Each reader returns the full output named in the row, including HF Datasets when reading from a stream.

Operation DataShoal PyArrow HF Datasets (streaming) HF Datasets (cached)
Read 10,000 chat records as Python rows 6.88 ms 7.92 ms 13.59 ms 7.21 ms
Read only the text column of 10,000 chat records 2.94 ms 3.26 ms 9.15 ms 3.45 ms
Read 250,000 integer IDs as Python rows 9.00 ms 10.68 ms 12.44 ms 12.07 ms
Read 250,000 integer IDs into a NumPy array 3.89 ms 0.86 ms 1.99 ms 2.03 ms
Write 10,000 chat records to uncompressed Parquet 6.99 ms 7.50 ms Not measured Not measured

Benchmark details and reproduction

SafeTensors benchmarks

Median elapsed time for one 64 MiB integer tensor on an Apple M5 Ultra. Lower is faster.

Operation DataShoal SafeTensors 0.8.0 (Rust, NumPy interface)
Read the full tensor into owned bytes 2.89 ms 5.16 ms
Stream the tensor in owned 1 MiB chunks 2.34 ms 7.67 ms
Write the tensor to a local file 5.29 ms 4.83 ms

DataShoal publishes writes atomically. Benchmark details and reproduction

SafeTensors I/O chunk sizes

Bulk owned reads, positional reads into caller buffers, and vectored raw-buffer saves use up to 64 MiB per transfer, subject to TensorLimits.max_chunk_bytes. Vectored saves combine small buffers without copying them into a second payload. Default archive.chunks() output and file-copy scratch buffers use up to 8 MiB.

The warm Linux arm64 tmpfs sweep used 17 rounds for a 256 MiB native owned read and 21 rounds for a 64 MiB vectored write. Lower is faster. The 64 MiB cap gave the fastest measured read and stayed within 0.22 ms of the fastest write in the sweep.

Chunk limit Read 256 MiB Write 64 MiB
64 KiB 21.23 ms
1 MiB 20.45 ms 41.82 ms
2 MiB 21.04 ms 41.37 ms
4 MiB 20.49 ms 41.53 ms
8 MiB 21.69 ms 41.32 ms
16 MiB 20.63 ms 41.26 ms
32 MiB 20.28 ms 41.51 ms
64 MiB 20.15 ms 41.48 ms

The paired write sweep covered 1–64 MiB. An independent 64 KiB write sweep measured 42.41 ms. Benchmark methods

Native accelerator benchmarks

Speedup of the current JIT accelerator over the previous release on identical inputs. Each cell is the median ratio of 15 alternating rounds with both builds loaded in one process.

Entry point Used by Small Medium Large
LZ4 frame decode Xet downloads 2.00x 3.49x 4.12x
Keyed BLAKE3 (64 B / 4 KiB / 64 KiB) Xet hashing 1.26x 1.94x 3.23x
Content-defined chunking Xet uploads 1.48x 1.98x 2.10x
Positional tensor read (1 / 64 / 256 MiB) SafeTensors 1.00x 1.51x 2.56x
Level encoding Parquet writes 1.59x 1.79x 1.71x
Repetition levels Parquet reads 1.54x 1.66x 1.41x
Snappy page decode Parquet reads 1.32x 1.18x 1.17x
Page and footer metadata Parquet reads 1.18x 1.18x 1.19x

String, dictionary and record assembly spend their time creating Python objects and stay within 5% of the previous release. Text packing no longer attaches a cached UTF-8 copy to every non-ASCII input string. That copy previously kept 15.3 MiB alive after writing a 15.7 MiB file. Measured on x86-64 with CPython 3.14.4. Reproduce with benchmarks/native.py

Attributions and citations 📚

DataShoal implements the Xet protocol for uploads to and downloads from the Hugging Face Hub. Please credit Hugging Face’s Xet team when citing the protocol.

Work Authors / project Reference
DataShoal ModelCloud.ai, @qubitiium, and DataShoal contributors Project
Xet Hugging Face’s Xet team and contributors Protocol specification · Reference implementation
SafeTensors SafeTensors contributors File format · Reference implementation

Cite DataShoal, Xet and SafeTensors (BibTeX)

@misc{modelcloud_datashoal,
  author = {{ModelCloud.ai} and {@qubitiium} and {DataShoal contributors}},
  title  = {{DataShoal}},
  url    = {https://github.com/ModelCloud/DataShoal}
}

@misc{huggingface_xet_protocol,
  author = {{Hugging Face}},
  title  = {{Xet Protocol Specification}},
  url    = {https://huggingface.co/docs/xet/en/index}
}

@misc{safetensors_format,
  author = {{SafeTensors contributors}},
  title  = {{SafeTensors}},
  url    = {https://github.com/safetensors/safetensors}
}

Used by

GPT-QModel uses DataShoal to streamline and accelerate data processing for LLM quantization. Project

Metadata

Release files for datashoal 0.1.1

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

Source distribution (sdist)

Source distribution for datashoal 0.1.1
File Size Uploaded Provenance Actions
datashoal-0.1.1.tar.gz 96.2 kB Without provenance Details for datashoal-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 201.0 kB

Release files / datashoal-0.1.1.tar.gz

Download URL datashoal-0.1.1.tar.gz
Size 96.2 kB
Tags Source
SHA-256 checksum
How to use checksums
72f31a132b894f55cb625482a16189aa1f804b9e2304235f0a7cef4391b60851
BLAKE2b-256 checksum
How to use checksums
d65996d24aa6e9d39ba4250f3b6151c3d9421bceb0ab4abc4ab5a4863beb9243
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / datashoal-0.1.1-py3-none-any.whl

Download URL datashoal-0.1.1-py3-none-any.whl
Size 104.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5dc7dab1bf2e7b7937f4019230b319765bf3f159978f7c0b1baaf36e0a3c8a51
BLAKE2b-256 checksum
How to use checksums
86043f4fe67b9a6869ffacd1cd06d871357f254d608cad30529439eafae4af1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for datashoal 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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