Skip to main content

microbiorust 🦀

Python bindings for microBioRust — a high-performance, modular bioinformatics toolkit written in Rust.

microbiorust provides fast and memory-efficient bioinformatics functionality to Python users by leveraging the power of Rust, exposed through PyO3. This package aims to offer an alternative to libraries like Biopython, with a focus on speed, correctness, and extensibility.


Installation

pip install microbiorust

to use the Python tests with pytest

python3 -m pytest -s tests/test_mbr.py

Wheels are available for Linux, macOS and Windows (Python 3.10+). No Rust toolchain required. (no requirement to install Rust)

Build from source

If you prefer to build from source using maturin:

pip install maturin
git clone https://github.com/microBioRust/microBioRust
cd microbiorust-py
maturin develop --features extension-module

To verify the Python module functions are correctly exposed from Rust:

cargo test

Features

  • Fast parsers for GenBank and EMBL formats
  • Fast parsers for BLAST XML and tabular formats
  • Fast parser for MSA alignments — subset, purge_gaps, get_consensus
  • Write directly to GFF3, FAA, FNA and FFN formats
  • Typed collections, return type enforces what data is returned
  • Accurate feature extraction, gene, product, strand, start, stop, codon_start
  • Native JSON serialization to instantly export extracted data structures to standard JSON strings
  • Sequence metrics: hydrophobicity, amino acid counts and percentages
  • Python API for easy integration into existing pipelines
  • Built with Rust for memory safety and performance

Modules

microbiorust gbk — GenBank format

import microbiorust as mb

# Write directly to file — most efficient for large files
# all functions are also available for embl format parse_embl, embl_to_faa, embl_to_ffn etc.)
collection = mb.parse_gbk("genome.gbk")
collection.write_faa("output.faa")
collection.write_ffn("output.ffn")
collection.write_fna("output.fna")

# Flat access across whole genome file — returns FaaCollection
faa = mb.gbk_to_faa("genome.gbk")
# print valid protein fasta
for info in faa.values():
    print(f">{info.locus_tag}\n{info.faa}")

# Per-contig record access
for record in collection.values():
    # prints the contig id and sequence
    print(record.id(), record.sequence())

    # protein sequences
    for info in record.faa().values():
        # prints the protein fasta for each predicted protein in the record
        print(f">{info.locus_tag}\n{info.faa}")

    # nucleotide sequences
    for info in record.ffn().values():
        # prints the nucleotide fasta sequence of each predicted gene
        print(f">{info.locus_tag}\n{info.ffn}")

    # features
    features = record.features()
    # prints the features of each predicted gene by locus tag key
    if "b3304" in features:
        feat = features["b3304"]
        print(f"Gene: {feat.gene}, Product: {feat.product}")
        print(f"Location: {feat.start}..{feat.stop}, Strand: {feat.strand}")

# Convert collection to JSON string
json_str = collection.to_json()
print(json_str)
# Parse JSON string into Python dictionary
data = json.loads(json_str)

# Count proteins without loading sequences
count = mb.gbk_to_faa_count("genome.gbk")

# Convert annotations from gbk or embl to GFF3
mb.gbk_to_gff("genome.gbk", dna=True)

---

### EMBL format: illustrates use by calling on the submodule, can also be called directly as mb.embl_to_faa etc.

```python
from microbiorust import embl

# Extract protein sequences to FASTA
embl.embl_to_faa("input.embl", "output.faa")

# Extract nucleotide sequences to FASTA
embl.embl_to_fna("input.embl", "output.fna")

# Convert annotations to GFF3
embl.embl_to_gff("input.embl", "output.gff")

microbiorust seqmetrics — Sequence metrics

from microbiorust import seqmetrics

sequence = "MKTLLLTLVVVTIVCLDLGAVGNGSSLSEDKDNVHK"

# Hydrophobicity score
window_size = 5
score = seqmetrics.hydrophobicity(sequence, window_size)

# Amino acid counts
counts = seqmetrics.amino_counts(sequence)

# Amino acid percentages
percentages = seqmetrics.amino_percentage(sequence)

microbiorust align — Multiple sequence alignment

from microbiorust import align

# Subset a fasta format MSA by row and column e.g.
align.subset_msa_alignment("input.fasta", "ids.txt", "output.fasta")
where the first tuple (0,10) is a row-wise subset and
the second tuple (0,100) is a column-wise subset

microbiorust.blast — BLAST results

import microbiorust

results = microbiorust.parse_tabular("blast_results.tab")
for hit in results:
    print(hit["qseqid"], hit["pident"], hit["bitscore"])

Choice of the usage pattern

Goal Use
Write everything to file collection.write_faa() / write_ffn() / write_fna()
Get all proteins across a whole genome file gbk_to_faa()
Work per genome contig record parse_gbk() then record.faa() or record.ffn()
Features and sequences together parse_gbk() then record.sequences() + record.features()
Count proteins without loading gbk_to_faa_count()
Convert collection to JSON string collection.to_json()
Parse JSON string into Python dictionary json.loads()

Why Rust?

Rust gives microbiorust C-level performance with memory safety — no segfaults, no GIL limitations, and no need for NumPy or Pandas for core parsing operations. Large GenBank or EMBL files are parsed significantly faster than equivalent pure-Python implementations.


Documentation

Full documentation: https://microbiorust.github.io/docs/

Source: https://github.com/microBioRust/microBioRust


License

MIT

Metadata

Release files for microbiorust 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 microbiorust 0.2.0
File Size Uploaded Provenance Actions
microbiorust-0.2.0.tar.gz 35.1 kB Without provenance Details for microbiorust-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for microbiorust 0.2.0
File Actions
microbiorust-0.2.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for microbiorust-0.2.0-cp310-abi3-win_amd64.whl
microbiorust-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for microbiorust-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
microbiorust-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for microbiorust-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
microbiorust-0.2.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for microbiorust-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
microbiorust-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for microbiorust-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 14.8 MB

Release files / microbiorust-0.2.0.tar.gz

Download URL microbiorust-0.2.0.tar.gz
Size 35.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1fd2d300317c71969ea23b21f514edef50aff3100db7d0678baf3778eccd969e
BLAKE2b-256 checksum
How to use checksums
b9544630b8093fb816e577a32c2b11de057bd885606bb36809b1fc788c1bfa13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / microbiorust-0.2.0-cp310-abi3-win_amd64.whl

Download URL microbiorust-0.2.0-cp310-abi3-win_amd64.whl
Size 2.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a968344842a12e58123e3194073ff6544ef819bdde7534452fc0d9097124091d
BLAKE2b-256 checksum
How to use checksums
67a40a4add1a3d3ca268d740796e63556f92d6896cfa63fb339e429532a68969
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / microbiorust-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL microbiorust-0.2.0-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 3.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
adc42e7d2fd2560dac919bc5947920d6d26f2e0620e2b1d5372b17a7823e4eda
BLAKE2b-256 checksum
How to use checksums
b51250f15d268509609dbc4d7d1be255f5ac5023d2401f800203abc84862f4da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / microbiorust-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL microbiorust-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 3.1 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
ae6c0304f70c9a10d2c279f8c26def0d769a6ce469d81c4bf6adef643e4c2079
BLAKE2b-256 checksum
How to use checksums
d8c379a147ee9c6661dc6459e8779ca2c22f5d6639be9bcb0a41cd467dee5abb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / microbiorust-0.2.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL microbiorust-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Size 2.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a9e3b6a3ef72feb1404f364f056c7108b68d40369ee32dc6896cea1d430a1f7b
BLAKE2b-256 checksum
How to use checksums
7c0342207f561abd3e9f0b3108ab84c98cc56da603b8be2f4356ba53f9fd0a47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / microbiorust-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL microbiorust-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 2.9 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
70e871446d7053eb12d91168811ed388ed5df067f4e335169d7b3517c4985a43
BLAKE2b-256 checksum
How to use checksums
855ff176b5543a6a5828c0fee88780b573b77822fc2c7a33416e9edb027be88e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Security for microbiorust 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.

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.

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