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.10 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=None, layer="counts", chunk_size=5000, where=None) |
Convert a file to .h5ad, .h5seurat or .zarr (AnnData Zarr v3). The output format is chosen from the extension of dst. where={"cell_type": ["B", "T"]} writes only the matching cells, still streaming. |
pk.read(path, *, assay=None, 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=None, layer="counts", rows=None, where=None) |
Iterate over X as CSR row blocks (pk.MatrixChunk). where={"CellLine": "A549"} or rows= (mask, indices or ranges) selects rows; on h5ad and Zarr only those rows are read. |
pk.open_dask(path, *, chunk_size=5000, assay=None, layer="counts") |
X as a lazy dask.array of CSR row blocks, for scanpy's dask code paths. Needs dask[array]. |
Supported inputs: H5AD, MuData .h5mu (one modality, chosen with assay=),
H5Seurat (dgCMatrix or BPCells-backed), BPCells
directories, 10x HDF5, MatrixMarket, 10x Visium and Visium HD (Space Ranger
outs/, or one HD bin directory), 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)
where= and rows= select rows before anything is decoded. On h5ad and
Zarr the reader reads only the selected rows' part of the row pointer and
their slices of data/indices, so a filter costs what its rows cost:
for chunk in pk.open_stream("emt.h5ad", where={"CellLine": "A549", "Time": ["3d", "7d"]}):
... # chunk.row_offset is the chunk's first row in the full matrix
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.
Dask
open_dask wraps the same reader as a lazy dask.array: one block per
chunk_size rows, over every gene, read only when dask computes it. That is
the layout scanpy's dask code expects, so an exact PCA runs block by block
without loading X:
import anndata as ad
import scanpy as sc
import picklerick as pk
adata = ad.AnnData(pk.open_dask("atlas.h5ad", chunk_size=10_000)[:, hvg])
sc.pp.pca(adata, n_comps=50, svd_solver="covariance_eigh")
dask's own reductions (X.sum()) don't accept scipy sparse blocks; use
X.map_blocks or scanpy's functions, which work block by block. Install with
pip install scx-picklerick[dask].
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.6.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 |
|---|---|---|---|---|
| scx_picklerick-0.6.0.tar.gz | 426.3 kB | Without provenance | Details for scx_picklerick-0.6.0.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl |
| scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details for scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_aarch64.whl |
| scx_picklerick-0.6.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for scx_picklerick-0.6.0-cp310-abi3-macosx_11_0_arm64.whl |
Total release size: 17.7 MB
Release files / scx_picklerick-0.6.0.tar.gz
| Download URL | scx_picklerick-0.6.0.tar.gz |
|---|---|
| Size | 426.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f735baae1408f51a4ef8992a1e33195462e81c0588011f2f1deb62d9f2fd10b2
|
|
BLAKE2b-256 checksum How to use checksums |
99ea330f11a8767a58b335bcb9c6425efe99635b2abf13d6c6f623ea32c3ffd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ed7d548bf14201bcde70c8059120cd98fe3874401d677df10c9c8c483ef44d28
|
|
BLAKE2b-256 checksum How to use checksums |
62fa82359267a90446c807a3eb5f368cb3a254308638c0b363b7e1fed87d4a55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | scx_picklerick-0.6.0-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d9f7eac32a45c522123df9953b6f1b07cc066f06e66d276b0395d46adc437aa0
|
|
BLAKE2b-256 checksum How to use checksums |
4dd7af25212ad49f16d1c4bfeeceb093fbbedef9f9bae67bb6ada57006ef109f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Release files / scx_picklerick-0.6.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | scx_picklerick-0.6.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.1 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
864f0790ea060d62598ff8155f5eacc3dee5b0ab02f5f53eee5f591543858f90
|
|
BLAKE2b-256 checksum How to use checksums |
51e127591741ec72a2549fa5b697da94e55fe3cd3085f95e6123d84c573859e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.7
|
Security for scx-picklerick 0.6.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.