picklerick
Python bindings for SCX, a Rust engine that converts single-cell data between formats in bounded memory.
pip install scx-picklerick
import picklerick as pk
The PyPI distribution is named scx-picklerick because picklerick is too
close to an existing project name. The import name is picklerick.
Requires Python 3.14 or newer. Wheels are built for Linux (x86_64, aarch64) and macOS (arm64) and include a statically linked HDF5. You don't need a system HDF5.
Early release. The API below is the one meant to stay, but it may still change. Versions follow the scx engine. Please report problems at https://github.com/btraven00/scx/issues.
What it does
| Function | Purpose |
|---|---|
pk.convert(src, dst, *, dtype="f32", assay="RNA", layer="counts", chunk_size=5000) |
Convert a file to .h5ad or .h5seurat. The output format is chosen from the extension of dst. |
pk.read(path, *, assay="RNA", layer="counts", dtype="f32", chunk_size=5000) |
Read any supported input into an in-memory anndata.AnnData. |
pk.write_h5seurat(adata, path, *, assay="RNA", chunk_size=5000) |
Write an AnnData to H5Seurat, in the SeuratDisk layout. |
pk.inspect(path) |
Return shape, columns, layers and nnz statistics without reading the matrix. |
pk.open_stream(path, *, chunk_size=5000, assay="RNA", layer="counts") |
Iterate over X as CSR row blocks (pk.MatrixChunk). |
Supported inputs: H5AD, H5Seurat (dgCMatrix or BPCells-backed), BPCells
directories, 10x HDF5, MatrixMarket, and AnnData Zarr. Engine errors are
raised as pk.PickleRickError.
convert streams the matrix in chunks of chunk_size cells, so peak
memory does not grow with the number of cells. When converting to H5Seurat
from a source that has a counts layer, X is treated as normalised data:
X is written to the Seurat data slot and the counts layer to the
counts slot.
Examples
import picklerick as pk
pk.convert("pbmc3k.h5seurat", "pbmc3k.h5ad")
pk.convert("pbmc3k.h5ad", "pbmc3k.h5seurat")
adata = pk.read("pbmc3k.h5seurat") # AnnData
pk.write_h5seurat(adata, "copy.h5seurat")
pk.inspect("atlas.h5ad")["n_obs"]
Streaming
open_stream yields CSR row blocks without loading the whole matrix or
building an AnnData object. Decoding runs on a background thread a few
chunks ahead of the consumer. The numpy arrays take ownership of the
decoded buffers, so there is no copy per chunk.
import numpy as np
import picklerick as pk
gene_sums = None
for chunk in pk.open_stream("atlas.h5ad", chunk_size=5000):
if gene_sums is None:
gene_sums = np.zeros(chunk.n_vars)
gene_sums += np.bincount(chunk.indices, weights=chunk.data, minlength=chunk.n_vars)
For deflate-compressed H5AD, chunks are decompressed on all cores. HDF5's own filter pipeline would decompress them on a single core.
Peak RSS and wall time for a per-gene-sum workload (bench/python/,
release build, chunk 5000, 16 cores):
| dataset | size | eager read_h5ad |
anndata backed | open_stream |
|---|---|---|---|---|
| pbmc3k | 29 MB | 0.15 GB / 0.42 s | 0.15 GB / 0.43 s | 0.15 GB / 0.44 s |
| norman | 79 MB | 0.24 GB / 1.16 s | 0.23 GB / 1.03 s | 0.11 GB / 0.42 s |
| hlca | 5.7 GB | 18.2 GB / 50 s | 0.93 GB / 30 s | 0.55 GB / 17 s |
Peak memory grows with chunk_size: HLCA uses 0.55 GB at 5000 and 3.6 GB at
50000.
Development
From the repository root:
pixi run -e py test-picklerick # debug build + pytest
pixi run -e py install-picklerick-release # before any benchmarking
A debug build is about 3× slower at HDF5 decoding, so use the release build
for timings. Tests use the small fixtures tracked in git. Tests that need the
large local fixtures (pixi run -e test fixtures) are skipped, with the
reason shown, when those fixtures are missing.
License
MIT.
Metadata
Release files for scx-picklerick 0.4.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 | |
|---|---|---|---|
| scx_picklerick-0.4.0.tar.gz | 236.8 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scx_picklerick-0.4.0-cp314-abi3-manylinux_2_28_x86_64.whl | CPython 3.14 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| scx_picklerick-0.4.0-cp314-abi3-manylinux_2_28_aarch64.whl | CPython 3.14 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| scx_picklerick-0.4.0-cp314-abi3-macosx_11_0_arm64.whl | CPython 3.14 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 14.1 MB
Release files / scx_picklerick-0.4.0.tar.gz
| Download URL | scx_picklerick-0.4.0.tar.gz |
|---|---|
| Size | 236.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c587a491d7d5b13f40886e301b6693c26540ef27a1350e8e649e0ed541c3b4ff
|
|
BLAKE2b-256 checksum How to use checksums |
e8a5e9bf0c5a68f7f93e34b0cf1b042731cdad12e7a0b9535b98b583ba31a576
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / scx_picklerick-0.4.0-cp314-abi3-manylinux_2_28_x86_64.whl
| Download URL | scx_picklerick-0.4.0-cp314-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0ed8e203fcac6cd5450adb977a7b3fb879992da667f603ce54b0543c9c767d9a
|
|
BLAKE2b-256 checksum How to use checksums |
b759be785f077ba97b98e0d7e6b6be9792492efb94f42dbca34a97b4c180b453
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / scx_picklerick-0.4.0-cp314-abi3-manylinux_2_28_aarch64.whl
| Download URL | scx_picklerick-0.4.0-cp314-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.9 MB |
| Tags | CPython 3.14 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
400da220c83c972fa5a377cd8566a87e5898813ef65ac2949c647b8e29b3f7b0
|
|
BLAKE2b-256 checksum How to use checksums |
530bdcf5430080edde441115dc1dac04541615b74bb75f4ffb97314f7462375d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / scx_picklerick-0.4.0-cp314-abi3-macosx_11_0_arm64.whl
| Download URL | scx_picklerick-0.4.0-cp314-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.14 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
498f3f98a0ea6f766c28a717d7e9d01dbc9d6a5bf8bc04e4fea53640843aaa5e
|
|
BLAKE2b-256 checksum How to use checksums |
94a288a642e65c33f5195332fb88b98e0e5912b2ab832bb4bc50160d4cd7b276
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|