Skip to main content

High-performance zero-copy tensor protocol

Project description

Gemini_Generated_Image_v39t46v39t46v39t

Tenso

High-Performance, Zero-Copy Tensor Protocol for Python.

Overview

Tenso is a specialized binary protocol designed for one thing: moving NumPy arrays between backends instantly.

It avoids the massive CPU overhead of standard formats (JSON, Pickle, MsgPack) by using a strict Little-Endian, 64-byte aligned memory layout. This allows for Zero-Copy deserialization, meaning the CPU doesn't have to move data—it just points to it.

Benchmark

Scenario: Reading a 64MB Float32 Matrix (Typical LLM Layer) from memory.

Format Read Time Write Time Status
Tenso 0.006 ms 6.76 ms Fastest & AVX-512 Safe
Arrow 0.009 ms 8.54 ms Heavy Dependency
Pickle 2.98 ms 3.19 ms Unsafe (Security Risk)
Safetensors 3.23 ms 9.41 ms -
JSON Too slow to measure

Installation

pip install tenso

Usage

Network

import numpy as np
import tenso

# Create a tensor
data = np.random.rand(100, 100).astype(np.float32)

# Serialize to bytes
packet = tenso.dumps(data)

# Deserialize back
restored = tenso.loads(packet)

File I/O

# Save to disk
with open("weights.tenso", "wb") as f:
    tenso.dump(data, f)

# Load from disk
with open("weights.tenso", "rb") as f:
    loaded_data = tenso.load(f)

Protocol Specification

Tenso uses a Hybrid Fixed-Header format designed for SIMD safety.

  • Header (8 bytes): TNSO Magic, Version, Flags, Dtype, NDim.

  • Shape Block: Variable length (NDim * 4 bytes).

  • Padding: 0-63 bytes to ensure the Body starts at a 64-byte aligned address.

  • Body: Raw C-contiguous memory dump.

Tenso vs. The World

Feature Tenso Pickle Arrow Safetensors
Speed (Read) Instant Slow Instant Fast
Safety Secure Unsafe (RCE Risk) Secure Secure
Alignment 64-byte None 64-byte None
Dependencies NumPy Only Python PyArrow (Huge) Rust/Bindings
Best For Network/IPC Python Objects Dataframes Disk Storage

Why is Tenso 1500x faster than Pickle? Standard formats must copy data from the network buffer into a new NumPy array. Tenso uses Memory Mapping: it tells NumPy to point directly at the existing buffer. No copying, no CPU cycles.

Development

# Clone the repository
git clone https://github.com/yourusername/tenso.git
cd tenso

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run benchmarks
python benchmark.py

Requirements

  • Python >= 3.10
  • NumPy

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

tenso-0.2.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

tenso-0.2.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file tenso-0.2.0.tar.gz.

File metadata

  • Download URL: tenso-0.2.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for tenso-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a652caec71ed9f7b88987c399a33b0e5ed11a53b5b780e4891d4cbb962202662
MD5 4691de280f687fcc4b8648fdc6edffc7
BLAKE2b-256 a7d2ab8a99d871f7a5d2ead1c7549fc16753ec738d19e432a34a3ae4975b3bae

See more details on using hashes here.

File details

Details for the file tenso-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tenso-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for tenso-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05a2d0d0da8f5dc25206d9998ce9069b856611ce682f880f1f01f61a0c1f72a7
MD5 9e61dfee1f0fdb3fb64b7797b58711a7
BLAKE2b-256 c0ded4bc4e48b1b8fc2df5b0989db361c06b0a68c227f4c7fa82bb3b4010bf02

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