High-performance, modern Python library for HTS data (BAM, CRAM, VCF, etc.)
Project description
Bamboo
High-performance, modern Python access to high-throughput sequencing data.
Bamboo is the spiritual successor to pysam. It provides a fast, ergonomic, and data-science-native Python interface to the core HTS formats (BAM, SAM, CRAM, VCF, BCF, and related index formats).
Why Bamboo?
- pysam is showing its age: The Cython wrapper around htslib is powerful but has ergonomic, performance, and integration limitations in 2026-era Python data workflows.
- The world moved on: We now have excellent pure-Rust parsers (
noodles), Arrow as the lingua franca of data, Polars, DuckDB, cloud object stores as first-class citizens, and a strong desire for zero-copy and streaming access. - Real production needs: Large cohorts, long-read data, cloud-native pipelines, single-cell scale, and tight integration with the rest of the scientific Python stack.
Bamboo aims to be the library you actually want to use when writing modern genomics code in Python.
Goals
- Blazing fast — Rust core (built on or alongside
noodleswhere it makes sense). - Pythonic & delightful — Modern API design, great error messages, context managers, iterators that feel native.
- Data-native — First-class Arrow support.
bam.records()should be able to give you a Polars DataFrame or pyarrow Table with tags as columns with minimal friction. - Cloud first — Excellent support for reading directly from S3, GCS, Azure Blob, with smart caching and range requests.
- Safe & correct — Memory safety from Rust + extensive testing against real-world data and edge cases.
- Interoperable — Play nicely with existing ecosystems (pysam compatibility shims where helpful, but not at the cost of a better design).
- Minimal dependencies for the core path.
Current Status
MVP: BAM + CRAM reading, columnar Arrow export, pysam parity CI, pileup (htslib).
Implemented today:
- Rust workspace (
bamboo-core,bamboo-io,bamboo-noodles,bamboo-htslib,bamboo-py) bamboo.AlignmentFile— iteration, region fetch, indexed fetch, BAM writebamboo.CramFile— CRAM decode with external reference, columnar + pileup- VCF/BCF readers with Arrow export
- Columnar scan to PyArrow via
read_columns()/to_arrow()(BAM + CRAM) - pysam parity tests on tiny fixtures and 50k-read synthetic cohort data
from bamboo.compat import pysamdrop-in shim — see MIGRATION.md- Cloud I/O:
s3://,gs://,https://,file:// - Pileup via htslib (optional build feature)
Still planned:
- PyPI publish (
bamboo-hts) + Bioconda merge - Unified
AlignmentFile(..., "rc")for CRAM - SAM/CRAM writing, CSI/tabix, coverage APIs
- Parity on messy production files (long reads, exotic tags)
Installation
pip install bamboo-hts
import bamboo # Python module name (not bamboo-hts)
Note: PyPI package is
bamboo-htsbecausebamboois an unrelated imaging library.
Optional extras:
pip install bamboo-hts[polars] # Polars adapter
pip install bamboo-hts[pandas] # Pandas adapter
Conda (after Bioconda recipe is merged):
conda install -c bioconda -c conda-forge bamboo-hts
Wheels bundle htslib — no system libhts or maturin required. See PACKAGING.md for release and conda-build details.
Development
python3.12 -m venv .venv
source .venv/bin/activate
pip install maturin pyarrow pytest 'pysam>=0.22'
maturin develop --release --features htslib
pytest
Smoke-test a release wheel locally: ./scripts/verify_wheel.sh
Generate test fixtures:
cargo run -p bamboo-noodles --example generate_fixtures
Quick Start
Migrating from pysam? Start with MIGRATION.md — one-line import swap, API table, validation checklist.
Killer workflow (indexed region → Arrow → Polars QC):
import bamboo as bm
table = bm.read_columns(
"cohort.bam",
columns=["qname", "rname", "pos", "mapq", "flag"],
region="chr1:1000000-5000000",
min_mapq=30,
)
df = bm.to_polars(table) # requires polars
print(df.group_by("rname").len())
Runnable demo: python examples/cohort_region_qc.py tests/data/tiny.bam --region chr1:100-500
Record iteration (pysam-familiar):
import bamboo as bm
with bm.AlignmentFile("aligned.bam") as bam:
for read in bam.fetch(region="chr1:1000000-1001000"):
print(read.query_name, read.reference_start, read.cigarstring)
See also examples/read_bam.py.
Cloud and remote paths
Bamboo reads BAMs (and sidecar .bai indexes when present) from local paths and cloud URIs through the same API:
import bamboo as bm
# Local path or file:// URI
with bm.AlignmentFile("aligned.bam") as bam:
...
# S3 (uses default AWS credential chain: env vars, ~/.aws, IAM role, etc.)
with bm.AlignmentFile("s3://my-bucket/cohort/sample.bam") as bam:
...
# GCS (uses Application Default Credentials / GOOGLE_APPLICATION_CREDENTIALS)
with bm.AlignmentFile("gs://my-bucket/cohort/sample.bam") as bam:
...
# HTTPS (public or pre-signed URLs)
with bm.AlignmentFile("https://example.com/public/sample.bam") as bam:
...
Index discovery tries sample.bam.bai then sample.bai next to the BAM URI. For indexed fetch(), the .bai must be reachable at one of those locations.
Writing BAMs
BAM writing uses local paths today (wb / w mode). Copy reads from an existing file with a pysam-style template header:
import bamboo as bm
with bm.AlignmentFile("input.bam") as src:
with bm.AlignmentFile("output.bam", "wb", template=src) as out:
for read in src:
out.write(read)
Or supply a reference dictionary when creating a new file:
with bm.AlignmentFile("output.bam", "wb", header={"chr1": 248956422}) as out:
out.write(read)
Quick Vision for the API
import bamboo as bm
# Open a BAM from local disk or a cloud URI
with bm.AlignmentFile("aligned.bam") as bam:
for read in bam.fetch(region="chr1:1000-2000"):
print(read.query_name, read.reference_start)
df = bm.to_polars(bam.to_arrow())
# VCF support is planned
# with bm.VariantFile("cohort.vcf.gz") as vcf:
# variants = vcf.to_polars()
The exact API will be refined with user feedback. The north star is: "it should feel like it was designed in 2025 for people who live in Polars/Jupyter/cloud environments", not "a thin wrapper over C structs".
Contributing
We are at the very beginning. Feedback on API design, performance targets, and must-have features is extremely welcome.
License
MIT
Name
"Bamboo" — fast-growing, strong yet flexible, and a nice break from the pyhts/pysam naming crowd. Also: "Bamboo for your BAMs".
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bamboo_hts-0.1.0.tar.gz.
File metadata
- Download URL: bamboo_hts-0.1.0.tar.gz
- Upload date:
- Size: 69.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f281221bdc0b7b1275a585f8b32ce81abfc5bd47a2e7ef6186e335781c28480f
|
|
| MD5 |
ce34ca361a273d113248a802fca89f22
|
|
| BLAKE2b-256 |
cfb7d7e47fe8b58495868dcbe374478f870cca1978dce717db24800217f1f0e5
|
File details
Details for the file bamboo_hts-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: bamboo_hts-0.1.0-cp312-cp312-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebbfb37bf760a2cec780c9ce53ffc5b20daaeb8d2e499e4b1878a21e5be758fc
|
|
| MD5 |
3461b7c52eeac99b90727739f6686fd5
|
|
| BLAKE2b-256 |
b49e7e60499d8c143153c8e25eab8c84c580c927a2d82f917372c353264596f3
|
File details
Details for the file bamboo_hts-0.1.0-cp312-cp312-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: bamboo_hts-0.1.0-cp312-cp312-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db86adc878bbd2108c8bb7c226a2ceb5aa43e9dcbc53eb7985c273f0045c7377
|
|
| MD5 |
991e0406aa89f9cfd46d05068bfebfdf
|
|
| BLAKE2b-256 |
0c94d579bd4693d270d8860a32ec37b5aca1c15c8a0303d58845e7fa55aa7f6c
|
File details
Details for the file bamboo_hts-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: bamboo_hts-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
639a5c16913fb9cce9fdc5afcbfb95004864e85b1a90e12cfc37eff539f8b60b
|
|
| MD5 |
916c0032d7b2f9f085864558cb01f235
|
|
| BLAKE2b-256 |
64430bfa1e26b3aa6016d10576a2c4c05c4fa9595d72150dd2b4b7d31907b3fd
|
File details
Details for the file bamboo_hts-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: bamboo_hts-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e36e7dddecd60eb1b67a38b697b9c6445bb55532e1e9e6bfc668103e27666f82
|
|
| MD5 |
d9c15e160b735885a628f45c237eb3cf
|
|
| BLAKE2b-256 |
f72d917b503699dbb16d863afe809296c5da57a5d2f672af8d36b3228752dcfe
|