SampleShard Python
Python implementation of the SampleShard format for storing training samples.
Installation
pip install sampleshard
# With optional compression support
pip install sampleshard[compression]
# With optional xxhash support (faster hashing)
pip install sampleshard[hash]
# All optional dependencies
pip install sampleshard[all]
Quick Start
from sampleshard import SampleShardWriter, SampleShardReader
# Writing samples
with SampleShardWriter("train.smpl") as w:
w.add_sample(1, {"input": [1, 2, 3], "label": 0})
w.add_sample(2, {"input": [4, 5, 6], "label": 1})
w.add_sample(3, {"input": [7, 8, 9], "label": 2})
# Reading samples
with SampleShardReader("train.smpl") as r:
# Get sample count
print(f"Total samples: {r.sample_count()}")
# Random access by ID
sample = r.get_sample(1)
print(sample) # {"input": [1, 2, 3], "label": 0}
# Check if sample exists
if r.has_sample(2):
print("Sample 2 exists!")
# Iterate all samples
for sample_id, sample in r:
print(f"Sample {sample_id}: {sample}")
# Batch access
batch = r.get_batch([1, 2, 3])
range_batch = r.get_batch_by_range(0, 10)
Features
- Fast random access by sample ID (O(1) lookup)
- Deterministic iteration order
- Metadata-safe: Reserved entries (starting with
__) excluded from sample counts - Memory-mapped access for zero-copy reads
- Optional compression (zstd, lz4)
- CRC32C checksums for data integrity
File Format
SampleShard uses the .smpl extension and the Shard v2 binary format:
- 64-byte header with magic bytes
SHRD - Role byte = 0x02 (Sample)
- 48-byte index entries with xxHash64 name hashes
- JSON-encoded sample data
- CRC32C checksums per entry
Interoperability
SampleShard files created with Python can be read by:
- Go:
agentscope/cowrie/ucodec.OpenSampleShard() - TypeScript:
@sampleshard/core
License
MIT
Metadata
Release files for sampleshard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sampleshard-0.1.0.tar.gz | 17.6 kB | Without provenance | Details for sampleshard-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sampleshard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for sampleshard-0.1.0-py3-none-any.whl |
Total release size: 35.5 kB
Release files / sampleshard-0.1.0.tar.gz
| Download URL | sampleshard-0.1.0.tar.gz |
|---|---|
| Size | 17.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8dd31835538f0a9352f58b6a45868ad6d61e8526e1d95f06564e5e05ff971847
|
|
BLAKE2b-256 checksum How to use checksums |
15dd81dbaa35830bac28b9493218cad69da69e67d78132cf5ef511b3d696cd71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / sampleshard-0.1.0-py3-none-any.whl
| Download URL | sampleshard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f49ad989b0a9250740faa29c6da791bde43771d34c68f67682a39f48c222c7c0
|
|
BLAKE2b-256 checksum How to use checksums |
c7172ac871d45ae66964093261392d567827c631073a64dfdce89c30edaf45ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for sampleshard 0.1.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.
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.