Skip to main content

Binsparse Python Reference Implementation

This library is a reference implementation of the Binsparse Binary Sparse Format Specification written using Python.

Binsparse is a cross-platform, embeddable format for storing sparse matrices and tensors. This library implements Binsparse bindings for NumPy NPZ, HDF5, and Zarr containers, with conversion interfaces for NumPy, SciPy, PyTorch, and PyData/Sparse.

Python Binsparse Interface

The primary interface consists of load_binsparse and save_binsparse. These functions select a container from the path extension (.npz, .h5/.hdf5, or .zarr) and read or write a BinsparseTensor:

from binsparse import load_binsparse, save_binsparse

tensor = load_binsparse("input.h5")
save_binsparse(tensor, "output.npz")

Parsed tensors expose their logical shape, number_of_stored_values, optional fill value, and the arrays that define their storage format. Concrete tensor classes represent the predefined Binsparse formats, including dense vectors and matrices, compressed sparse rows and columns, doubly compressed matrices, and coordinate formats. CustomTensor and the level classes (DenseLevel, SparseLevel, and ElementLevel) represent arbitrary level-based format descriptors.

For applications that already manage their own storage objects, the lower-level BinsparseContainer interface separates tensor parsing and serialization from the physical container. Adapters are provided for NPZ mappings, HDF5 files, Zarr groups, and in-memory descriptors and buffers. Use BinsparseTensor.parse(container) to read through an adapter and tensor.serialize(container) to write through one.

The alias option controls whether predefined format names such as CSR are preserved or expanded to custom level descriptors. The copy option allows a caller to request a copy, permit whichever representation is required, or require a zero-copy operation when the source and destination support it.

binsparse.conversions exports the following conversion functions:

  • NumPy: from_numpy and to_numpy
  • SciPy: from_scipy and to_scipy
  • PyTorch: from_torch and to_torch
  • PyData/Sparse: from_sparse and to_sparse

NumPy support is included by default; the other adapters require their corresponding optional dependency.

SciPy, PyData/Sparse, and PyTorch COO imports sort indices and sum duplicate entries before constructing a Binsparse tensor, without modifying the source. copy=False requires canonical (sorted, duplicate-free) input; PyTorch COO tensors must be coalesced first. PyTorch CSR/CSC imports rely on PyTorch's sorted, unique index invariants.

Source

The source code for binsparse is available on GitHub at https://github.com/Binsparse/binsparse-reference-python

Installation

binsparse is available on PyPi, and can be installed with pip:

pip install binsparse

Metadata

Release files for binsparse 0.1.4

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

Source distribution (sdist)

Source distribution for binsparse 0.1.4
File Size Uploaded
binsparse-0.1.4.tar.gz 71.8 kB Details

Built distribution (wheel)

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

Total release size: 95.1 kB

Release files / binsparse-0.1.4.tar.gz

Download URL binsparse-0.1.4.tar.gz
Size 71.8 kB
Tags Source
SHA-256 checksum
How to use checksums
812b38600965fe7a85c9bf899941c548711d1d0ba227fc46050422981d4f6884
BLAKE2b-256 checksum
How to use checksums
ee9abcf439dd408c15fe8ed296976e07b7d682ba1baa39e16887f3052ecd85ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release files / binsparse-0.1.4-py3-none-any.whl

Download URL binsparse-0.1.4-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e77ab364f1b6e22456fa377c3a6804a41d7986b887e4acd748b923e6350977d0
BLAKE2b-256 checksum
How to use checksums
90e67a97b1e81cce85ceab0f7750d2a35cde879281ffd3eb65351c73e0f2ac8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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