Skip to main content

🔗🐍🧬 rammappy Stars

PyO3 bindings and zero-copy Python interface to rammap, the Rust implementation of minimap2.

Release PyPI ruff ty

⚠️ Warning

This library is still in active development, with API refinements possible between minor versions.


🗺️ Overview

rammappy provides a zero-dependency, immutable, thread-safe Python OOP interface over rammap-core (Python >=3.12, abi3-py312 + free-threaded Python 3.14t):

  • Zero third-party dependencies: Pure Rust extension + Python standard library (collections.abc.Buffer & memoryview).
  • PEP 3118 zero-copy FFI in both directions:
    • Inputs: Accept bytes, bytearray, memoryview slices, mmap.mmap, or Record instances directly without copying (strictly rejecting str).
    • Outputs: MappingBatch and Sketch expose contiguous Struct-of-Arrays memoryview columns (offsets, scores, target_ids, cigar_data, cigar_offsets, etc.) that work natively in Python stdlib and wrap in $O(1)$ zero-copy via numpy.asarray(...) or pyarrow.
  • Immutable & thread-safe (#[pyclass(frozen)]): Index and Aligner share Arc<Index> in $O(1)$ without serialization, and map_batch runs lock-free across an isolated Rayon thread pool with per-worker DP/chaining scratch reuse.

🔧 Installing

uv add rammappy

For local development:

just install

💡 Examples

🧬 Parsing FASTA/FASTQ Files & Zero-Copy mmap

All file readers, memory parsers, and chunk streamers yield immutable Record objects:

import mmap
import rammappy

# Optional context manager deterministically closes the OS file descriptor
with rammappy.FastxReader("sequences.fq.gz") as reader:
    for record in reader:
        mv = memoryview(record)  # zero-copy PEP 3118 byte view of record.sequence
        assert len(mv) == len(record)

# Parse directly from an mmap or memoryview slice without copying
with open("reference.fa", "rb") as fh, mmap.mmap(fh.fileno(), 0, access=mmap.ACCESS_READ) as mm:
    records = rammappy.parse_fasta_bytes(mm)

# Chunk-fed streaming (subclasses SequenceStreamer)
streamer = rammappy.FastaStreamer(rna_to_dna=False)
streamer.push(b">seq1\nACGT\n>seq2\nGGGG\n")
streamer.finalize()
for record in streamer:
    assert isinstance(record, rammappy.Record)

🧠 Building an In-Memory Index & Aligner

Index.build accepts Record instances or (name, sequence) byte-buffer tuples:

import rammappy

records = [
    rammappy.Record(b"chr1", b"ACGT" * 1000),
    rammappy.Record(b"chr2", b"TGCA" * 1000),
]

index = rammappy.Index.build(records, k=15, w=10, threads=4)
assert b"chr1" in index
assert index[b"chr1"][:4] == b"ACGT"

# Share Arc<Index> in O(1) across one or more immutable Aligners
# Pass preset=None for pure minimap2 -c defaults without preset overrides
aligner = rammappy.Aligner(index, preset=rammappy.Preset.Sr, threads=4)

⚙️ Immutable Configuration (MapOptions & AlignFlags)

Configuration objects are immutable (frozen) value objects supporting .replace(...) (and Python 3.13+ copy.replace), making accidental lost-mutation bugs impossible:

from rammappy import AlignFlags, MapOptions, Preset, ScoringParams

opts = MapOptions.from_preset(Preset.Sr).replace(
    scoring=ScoringParams(match_score=3, mismatch_penalty=6),
    flags=AlignFlags.SHORT_READ | AlignFlags.ALL_CHAINS | AlignFlags.OUT_CIGAR,
)

custom_aligner = aligner.with_options(opts)

🔬 Parallel Batch Alignment (MappingBatch)

Aligner.map_batch returns a CSR MappingBatch supporting both lazy Python Sequence iteration (batch[query_idx] -> QueryMappings -> Mapping) and zero-copy PEP 3118 memoryview columns:

queries = [
    (b"q1", b"ACGT" * 20),
    (b"q2", b"TGCA" * 20),
]

batch = aligner.map_batch(queries)

# 1. Idiomatic OOP Sequence access (preserves CIGAR, cs, md, target_name)
for q_idx, hits in enumerate(batch):
    if hits:
        top = hits[0]
        assert top.cigar is not None

# 2. Zero-copy stdlib memoryview column slicing (CSR offsets in record indices)
offsets = batch.offsets
scores = batch.scores
cigar_offsets = batch.cigar_offsets
cigar_data = batch.cigar_data  # BAM uint32 words: (op_len << 4) | op_code

q0_scores = scores[offsets[0] : offsets[1]]

📊 Polymorphic Sequence Sketchers (Sketcher -> Sketch)

MinimizerSketcher, SyncmerSketcher, and RandstrobeSketcher inherit from Sketcher and return a Sketch container with both Minimizer indexing and zero-copy memoryview columns:

sketcher: rammappy.Sketcher = rammappy.MinimizerSketcher(k=15, w=10)
sketch = sketcher.sketch(b"ACTG" * 50)

first = sketch[0]
assert first.hash == sketch.hashes[0]
assert first.position == sketch.positions[0]

🔄 Upgrading from 0.1.x (Breaking Changes)

The 0.2.0 architecture redesign introduces an immutable OOP model, strict zero-copy PEP 3118 byte buffers, and zero runtime dependencies. See CHANGELOG.md for full release notes.

Area 0.1.x 0.2.0
Python version >=3.10 >=3.12 (abi3-py312, PEP 3118 Buffer)
Sequence / name FFI Accepted str or bytes Contiguous byte buffers (bytes, bytearray, memoryview, mmap) or Record (str raises TypeError)
Record signature Record(name, desc, seq, qual) Record(name, seq, *, description=None, quality=None)
FASTA/FASTQ readers Returned (name, seq) tuples All readers & streamers yield Record objects
Options & mutability In-place mutation (opts.scoring.match_score = 3, index.strip_sequences(), aligner.load_junctions_bed(...)) Immutable frozen types (opts.replace(...), index.without_sequences(), aligner.with_options(...), aligner.with_junctions_bed(...))
Batch alignment list[MappingIterator] / NumPy map_batch_numpy Zero-dependency CSR MappingBatch (Sequence[QueryMappings] + zero-copy memoryview columns, numpy.asarray-ready)
Sketchers MinimizerSketcher(w, k) -> list[Minimizer] MinimizerSketcher(k, w, *, is_hpc=False) (subclass of Sketcher) -> Sketch (Sequence[Minimizer] + memoryview columns)
Exceptions & Strand ValueError on missing contig; FastxReader swallowed I/O errors Dual-inheritance SequenceNotFoundError (KeyError), FormatError (ValueError), IndexIOError (OSError); Strand IntEnum (+1 / -1)

👏 Acknowledgments

We thank the original authors of rammap, Jeremy R. Wang and Heng Li, for their high-performance Rust implementation of minimap21.

📚 References

  1. Jeremy R. Wang and Heng Li. Memory-safe high-performance sequence mapping with rammap (2026). bioRxiv. 10.64898/2026.05.26.726289. ↩

Metadata

Release files for rammappy 0.2.0

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

Source distribution (sdist)

Source distribution for rammappy 0.2.0
File Size Uploaded Provenance Actions
rammappy-0.2.0.tar.gz 92.7 kB With provenance Details for rammappy-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for rammappy 0.2.0
File Interpreter ABI Platform Actions
rammappy-0.2.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for rammappy-0.2.0-cp312-abi3-win_amd64.whl
rammappy-0.2.0-cp312-abi3-manylinux_2_34_x86_64.whl CPython 3.12 abi3 Linux glibc 2.34+ x86-64 Details for rammappy-0.2.0-cp312-abi3-manylinux_2_34_x86_64.whl
rammappy-0.2.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for rammappy-0.2.0-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 2.5 MB

Release files / rammappy-0.2.0.tar.gz

Download URL rammappy-0.2.0.tar.gz
Size 92.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fc0c7f8aec26f7b05a99d12758e152ae4382e5598c7a1d75f1d98d6d48a20492
BLAKE2b-256 checksum
How to use checksums
af7e600e1cd9f1d9b0e854ba8fbced6855ee91217fc8725acfb52793608e4330
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 28, 2026.

Transparency log

Release files / rammappy-0.2.0-cp312-abi3-win_amd64.whl

Download URL rammappy-0.2.0-cp312-abi3-win_amd64.whl
Size 704.6 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
816bd263552e70ef13d82d038d4b268bd0dde62e192c74eab861bf457910d144
BLAKE2b-256 checksum
How to use checksums
e80ddb742449287e5b52070bf8f00e3489956aae9a786d9263139d6f899a56b4
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 28, 2026.

Transparency log

Release files / rammappy-0.2.0-cp312-abi3-manylinux_2_34_x86_64.whl

Download URL rammappy-0.2.0-cp312-abi3-manylinux_2_34_x86_64.whl
Size 909.0 kB
Tags CPython 3.12 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
6e8820cefb438715a5ff289f544eeae43e8ca3e5b3bc1ab76b551c3a2e3a7a05
BLAKE2b-256 checksum
How to use checksums
128348a416970d9f956f1a393ed707a1e057ebeb02268cde8aef71ad8be4873c
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 28, 2026.

Transparency log

Release files / rammappy-0.2.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL rammappy-0.2.0-cp312-abi3-macosx_11_0_arm64.whl
Size 786.3 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3297728887a64ac5b8d55c96c9d47e401930540cd6087a971733733554c6d84a
BLAKE2b-256 checksum
How to use checksums
8f07fcbc029d99a5f23dd9b2dc887e666e57ef860bd7904f1a0f5654d20e78d1
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 28, 2026.

Transparency log

Security for rammappy 0.2.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 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for rammappy-0.2.0.tar.gz

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 28, 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