Skip to main content

Python bindings for the zTensor library.

Project description

ztensor

Crates.io Docs.rs PyPI License: MIT

Simple tensor serialization format

Key Features

  • Simple Spec — Minimalist spec for easy parsing.
  • Zero-Copy Access — Instant memory-mapping (mmap) with no RAM overhead.
  • Efficient Writes — Supports streaming and append-only operations without rewriting files.
  • Future-Proof — Decouples physical storage from logical representation for long-term compatibility.

Ecosystem

  • Rust Core — High-performance, SIMD-aligned implementation.
  • Python API — First-class bindings for NumPy and PyTorch.
  • Universal Converters — CLI tools to easily convert Pickle, SafeTensors, and GGUF files.

Comparison

Feature zTensor SafeTensors GGUF Pickle HDF5
Zero-Copy Read ⚠️
Safe (No Exec)
Streaming / Append
Sparse Tensors
Compression
Quantization
Parser Complexity 🟢 Low 🟢 Low 🟡 Med 🔴 High 🔴 High

Installation

Python

pip install ztensor

Rust

[dependencies]
ztensor = "0.1"

CLI

cargo install ztensor-cli

Quick Start: Python

Basic Usage with NumPy

import numpy as np
from ztensor import Writer, Reader

# Write tensors
with Writer("model.zt") as w:
    w.add_tensor("weights", np.random.randn(1024, 768).astype(np.float32))
    w.add_tensor("bias", np.zeros(768, dtype=np.float32))

# Read tensors (zero-copy where possible)
with Reader("model.zt") as r:
    # Returns a numpy-like view
    weights = r.read_tensor("weights")
    print(f"Weights shape: {weights.shape}, dtype: {weights.dtype}")

PyTorch Integration

import torch
from ztensor import Writer, Reader

# Write PyTorch tensors directly
t = torch.randn(10, 10)
with Writer("torch_model.zt") as w:
    w.add_tensor("embedding", t)

# Read back as PyTorch tensors
with Reader("torch_model.zt") as r:
    # 'to="torch"' returns a torch.Tensor sharing memory with the file (if mmap)
    embedding = r.read_tensor("embedding", to="torch")
    print(embedding.size())

Sparse Tensors

Supports CSR (Compressed Sparse Row) and COO (Coordinate) formats.

import scipy.sparse
from ztensor import Writer, Reader

csr = scipy.sparse.csr_matrix([[1, 0], [0, 2]], dtype=np.float32)

with Writer("sparse.zt") as w:
    # Add CSR tensor
    w.add_sparse_csr("my_csr", csr.data, csr.indices, csr.indptr, csr.shape)

with Reader("sparse.zt") as r:
    # Read back as scipy.sparse.csr_matrix
    matrix = r.read_tensor("my_csr", to="numpy")

Compression

Use Zstandard (zstd) compression to reduce file size.

with Writer("compressed.zt") as w:
    w.add_tensor("big_data", data, compress=True)

Quick Start: Rust

Basic Usage

use ztensor::{ZTensorWriter, ZTensorReader, DType, Encoding, ChecksumAlgorithm};

// Write
let mut writer = ZTensorWriter::create("model.zt")?;
writer.add_tensor("weights", vec![1024, 768], DType::Float32, 
                  Encoding::Raw, data_bytes, ChecksumAlgorithm::None)?;
writer.finalize()?;

// Read
let mut reader = ZTensorReader::open("model.zt")?;
// Read as specific type (automatically handles endianness)
let weights: Vec<f32> = reader.read_tensor_as("weights")?;

Sparse Tensors

// Write CSR
writer.add_csr_tensor(
    "sparse_data",
    vec![100, 100],      // shape
    DType::Float32,
    values_bytes,        // standard LE bytes
    indices,             // Vec<u64>
    indptr,              // Vec<u64>
    Encoding::Raw,
    ChecksumAlgorithm::None
)?;

// Read CSR
let csr = reader.read_csr_tensor::<f32>("sparse_data")?;
println!("Values: {:?}", csr.values);

Compression

// Write with compression
writer.add_tensor(
    "compressed_data",
    vec![512, 512],
    DType::Float32,
    Encoding::Zstd, // Use zstd encoding
    data_bytes,
    ChecksumAlgorithm::Crc32c // Optional checksum
)?;

// Read (auto-decompresses)
let data: Vec<f32> = reader.read_tensor_as("compressed_data")?;

CLI

The ztensor CLI tool allows you to inspect and manipulate zTensor files.

Inspect Metadata

Print tensor names, shapes, and properties.

ztensor info model.zt

Convert Other Formats

Convert SafeTensors, GGUF, or Pickle files to zTensor.

# Auto-detect format from extension
ztensor convert model.safetensors -o model.zt

# Explicit format with compression
ztensor convert -f gguf -c llama.gguf -o llama.zt

# Delete originals after conversion
ztensor convert --delete-original *.safetensors -o model.zt

Compression Tools

# Compress an existing raw file
ztensor compress raw.zt -o compressed.zt

# Decompress a file
ztensor decompress compressed.zt -o raw.zt

Merge Files

Combine multiple zTensor files into one.

ztensor merge part1.zt part2.zt -o merged.zt

Supported Data Types

Type Description
float32, float16, bfloat16, float64 Floating point
int8, int16, int32, int64 Signed integers
uint8, uint16, uint32, uint64 Unsigned integers
bool Boolean

File Format

See SPEC.md for the complete specification.

License

MIT

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

ztensor-1.0.0.tar.gz (41.4 kB view details)

Uploaded Source

Built Distributions

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

ztensor-1.0.0-py3-none-win_amd64.whl (428.0 kB view details)

Uploaded Python 3Windows x86-64

ztensor-1.0.0-py3-none-win32.whl (385.9 kB view details)

Uploaded Python 3Windows x86

ztensor-1.0.0-py3-none-musllinux_1_2_x86_64.whl (959.3 kB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

ztensor-1.0.0-py3-none-musllinux_1_2_i686.whl (981.4 kB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

ztensor-1.0.0-py3-none-musllinux_1_2_armv7l.whl (945.4 kB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

ztensor-1.0.0-py3-none-musllinux_1_2_aarch64.whl (908.6 kB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

ztensor-1.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (747.8 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

ztensor-1.0.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (740.9 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

ztensor-1.0.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (823.4 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

ztensor-1.0.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (679.5 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

ztensor-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (687.0 kB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

ztensor-1.0.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl (765.4 kB view details)

Uploaded Python 3manylinux: glibc 2.5+ i686

ztensor-1.0.0-py3-none-macosx_11_0_arm64.whl (563.6 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file ztensor-1.0.0.tar.gz.

File metadata

  • Download URL: ztensor-1.0.0.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for ztensor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d66611d58ca79ec02fdd7101e3cc106468a8c694929c33a5604f55eb8207f48d
MD5 24a755252c09ec5542f51ae716d1a7a6
BLAKE2b-256 37a1316a977463544c19b977a1e736f6e3bb3911ba992f317116ed31fb768cfc

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: ztensor-1.0.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 428.0 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for ztensor-1.0.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7f552f9aa619c6d6ec19649ba7a9031241d47dc4ec4d26a2e3d66ed29c1cca43
MD5 94c37437aa2f8915bb7bd737c0ff08e8
BLAKE2b-256 a463b94f459238c862ef88139d56c04360fddced1b6284d3e4b35f260766a631

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-win32.whl.

File metadata

  • Download URL: ztensor-1.0.0-py3-none-win32.whl
  • Upload date:
  • Size: 385.9 kB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for ztensor-1.0.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 bd080e2dcfd7caf67d560776228b507af8ce15842ed13ca9cc6b0c43486cfa84
MD5 54401d8ca33553fc52cf434b0b39a287
BLAKE2b-256 f8d7ac64e8bc3419f37acf98201975c1457448e0a1bd944d86f8f822209cdac5

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cead8b118b3f11da43ee1b18105e2857a3bbb66507dc54653966424244eb887d
MD5 43fc2fdfa4137897f6544e4a524e09fe
BLAKE2b-256 71ef44c6c091761fd3537e72624c59fffeabe007d5151d9fefae03b561df37db

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 908088272b0d8e3933166a431470ee2534934dd4443070a0dcd70c14b401b044
MD5 aa6e2c69963516c7e740b478e1a4b102
BLAKE2b-256 b867b596e3bed383e127834de80acca1e81a6279e2e37e4133ef58b3e5d0bb1b

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 b867120df93829667e56fde6038134888f92ef7476a253170b17f901dd3091fe
MD5 384436ba50a18b765040091cb79a0e1f
BLAKE2b-256 34c56eb6438a2e8cc4cb058dec2ab37117a050d0ff182d92dafa32478b30e134

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 000d816f683d4e70d3ad0dcadae7b2b27540b253b3fd5dc05e97ccbe9f3d0334
MD5 aa99720af2af92dcc171369d099528cc
BLAKE2b-256 58661bd62452c162daf8a96542f0f705865e2b805a0ab5c7dc1c550b039898f1

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75e2445ea7cc964881eede8a7eacdfcaaf67b4174969c25901858a8c99c80281
MD5 3f1eaae035faeb276561b74bfef9c82d
BLAKE2b-256 bb5da60182d9b492d7354166db79605ce70c3395cb0562cd906197c793aead7d

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 11c7be1a938921ee72ddafa8be8a2ea24d33a17d61f2dba2951a8ade25ee545d
MD5 5dfdc34b4409734b6150f3b7ef611593
BLAKE2b-256 fda9e17acf3ee8ae638578e79dae4c2fa0ece15b92a13b41bfe0afdfce1a7950

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 79282bc6fa87b504c36ba8f6c7e1dc0b7398b8d38b9191fddbcc808be47d5be6
MD5 26f58acf05e751af0ee09ca75d334cef
BLAKE2b-256 ced7080dde48d384cd2b6d7f04395774f223c407c4211468a50979c6d9e065ff

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 adeb627d652f1ad9d9dbd7ff3a1ed90f2fc0b6c5c723254884b9b211f1450ad1
MD5 250c130c330cdb3166b33458ca6d3761
BLAKE2b-256 ac002d3b565c7ccae6a4de8b9fc6e4f753feb01252e92720a367223443589276

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 43770551c766fcfb2b307ee222861da1690005f92ee39e20305b4178516b0f43
MD5 bb4b92e08bc3d034d97cda608879dda5
BLAKE2b-256 e5853bf27b09c097a6d5aaac52fa1fa9a50a8c2a4d1f3bd0476adabefab431b3

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 9a1a104791aa4c8562b0a64831cb0a8bd1d66703600aec6b413b0f2423262b5c
MD5 a975844255a62ff716980523f51903b2
BLAKE2b-256 60a5d69cceb6fda2c822df3d9b41a1f66f9cb22af7c17667d76015e7aec68ef7

See more details on using hashes here.

File details

Details for the file ztensor-1.0.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ztensor-1.0.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 331d3e9e64392aa8440cf8c8612a8605506137dce716a8ff760dbde4340f4677
MD5 1c1f8a62731b1b43252285170cfc5136
BLAKE2b-256 af00961ca74c1ccb1d3742c135cb69bbb197e1aa20d95d75b0217b811cae1f2b

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