Skip to main content

PyPI Docs CI

bonsai-rs

Tree representations of single-cell data under Brownian motion. Python bindings for the bonsai-rs crate, a clean-room implementation of Bonsai (de Groot et al., Nature Biotechnology 2026, doi 10.1038/s41587-026-03220-2).

Raw UMI counts in, tree out. Sanity runs first, also in Rust, so the error bars Bonsai needs come from the counts rather than from nowhere.

Install

uv pip install bonsai-rs            # numpy only; dense counts
uv pip install "bonsai-rs[sparse]"  # adds scipy, for sparse counts
uv pip install "bonsai-rs[anndata]" # adds anndata, for bs.anndata

Wheels for Python 3.10 and up on Linux x86_64 and macOS.

Use

import bonsai_rs as bs

res = bs.bonsai_from_counts(counts, cell_totals=totals)  # cells x genes

res.tree  # parent array, branch lengths, leaf count
res.node_means  # posterior position of every node, ancestors too
xy = bs.layout(res.tree)  # (n_nodes, 2), edges run node -> parent
newick = bs.to_newick(res.tree, labels=cell_names)

verbose covers both Sanity and the tree search.

cell_totals is each cell's UMI total over all genes. Leave it out and the row sums are used, which is only right when counts holds every gene.

Counts in an AnnData? bs.anndata.bonsai(adata, layer="counts") reads the layer without a copy and leaves adata alone.

Already have means and standard deviations? bs.bonsai(means, sds).

Docs

gregorlueg.github.io/bonsai-rs: quickstart, the Sanity handover and its sharp edges, and the API reference.

Development

uv sync
uv run maturin develop --release
uv run pytest
uv run --group docs mkdocs serve

Licence

MIT. Built from the paper and its CC-BY-4.0 Supplementary Information only; see provenance in the repository. Cite the paper.

Metadata

Release files for bonsai-rs 0.4.0

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

Built distributions (wheels)

Table of built distributions (wheels) for bonsai-rs 0.4.0
File Interpreter ABI Platform Actions
bonsai_rs-0.4.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for bonsai_rs-0.4.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
bonsai_rs-0.4.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for bonsai_rs-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
bonsai_rs-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for bonsai_rs-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 41.2 MB

Release files / bonsai_rs-0.4.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL bonsai_rs-0.4.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 14.6 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d98d22c8a0b2f9a5b1259b214b92a58f1bff94595fa8deef922f701a8d61d3a1
BLAKE2b-256 checksum
How to use checksums
87aa5ee55a2eb89478ef66878562bcded2cc6e52e9a8b9078f2efca77e59ea8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Release files / bonsai_rs-0.4.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL bonsai_rs-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Size 12.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d0fd2b65a56c97bd134195786d9ad00d2163ba69bf53e6e7d99fae1784d7e1d2
BLAKE2b-256 checksum
How to use checksums
35a16a01fa9f91b678038c871c3953deb04939da45344ce7709063d96b4068f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Release files / bonsai_rs-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL bonsai_rs-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 13.7 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0594e72f33ebf6e608cc22fc8022d88b0f431e65e925b8369f22edad176f6055
BLAKE2b-256 checksum
How to use checksums
463cf3432c7ea7ef4d9ab42754950894060db655445c2a1aa3edbba08d38099b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 30, 2026.

Transparency log

Security for bonsai-rs 0.4.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.

Full provenance

All 3 files in this release have been uploaded with provenance metadata.

Select from 3 files

Attestation for bonsai_rs-0.4.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

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 Nov 30, 2026.

Transparency log

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.

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