Skip to main content

FM Index

CI codecov PyPI - Version PyPI - License PyPI - PythonVersion PyPI - Implementation PyPI - Types PyPI Downloads PyPI - Format Rust GitHub Repo stars

High-performance FM-index implementation powered by Rust,
designed for fast substring search on large texts and collections

Features:

  • Fast count / locate substring queries
  • Data-parallel optimizations across index construction and queries
  • Supports single text and multiple documents
  • Pickle serialization support for efficient index persistence
  • Optional disk-backed storage (on_disk=True)

Installation

pip install fm-index

FMIndex (Single Document)

What is FMIndex?

FMIndex builds a compressed index over a single string,
allowing fast substring search without scanning the original data.

Construction Complexity

  • Time / Space: O(|data|)

Example

from fm_index import FMIndex

genome = "ACGTACGTTGACCTGACTGACTGACTGACGATCGATCGATCGATCGATCG"
fm = FMIndex(data=genome)

FMIndex also supports disk-backed storage for a large document.
Set on_disk=True to keep its internal data on disk instead of holding it all in memory.

fm = FMIndex(data=genome, on_disk=True)

Count Substring Occurrences

Counts how many times a pattern appears.
Time complexity is independent of data size.

fm.count(pattern="GACTGACT")
# 2

Locate Substring Positions

Returns all starting offsets where the pattern occurs.

To improve throughput for high-frequency patterns,
FMIndex applies parallel execution to parts of the locate pipeline.

fm.locate(pattern="GACTGACT")
# [18, 14]

Iterative Locate (Streaming)

For large result sets, iter_locate provides a memory-efficient
iterator interface that yields positions lazily.

for pos in fm.iter_locate(pattern="GACTGACT"):
    print(pos)
# 18
# 14
  • Same results as locate
  • Does not allocate a result list
  • Suitable for streaming and early termination

MultiFMIndex (Multiple Documents)

MultiFMIndex extends FMIndex to support multiple documents
while keeping query time independent of corpus size

Query processing is internally parallelized where possible,
making multi-document search efficient in practice.

Construction Complexity

  • Time / Space: O(|''.join(data)| + len(data) log (len(data)))
from fm_index import MultiFMIndex

documents = [
    "政府はAI研究の支援を強化すると発表した。",
    "政府は新たなデータ活用方針を発表した。",
    "政府はサイバーセキュリティ対策を発表した。",
    "専門家はAI検索技術の進化に注目している。",
    "研究者は高速な検索アルゴリズムに注目している。",
    "オープンソース界隈では全文検索ライブラリに注目している。",
]

mfm = MultiFMIndex(data=documents)

MultiFMIndex also supports disk-backed storage for large documents.
Set on_disk=True to keep its internal data on disk instead of holding it all in memory.

mfm = MultiFMIndex(data=documents, on_disk=True)

Count Across All Documents

mfm.count_all(pattern="検索")
# 3

Count Per Document

mfm.count(pattern="検索")
# {3: 1, 4: 1, 5: 1}

# Count within a specific document
mfm.count(pattern="検索", doc_id=3)
# 1

Locate Per Document

mfm.locate(pattern="検索")
# {5: [13], 4: [7], 3: [6]}

# Locate within a specific document
mfm.locate(pattern="検索", doc_id=3)
# [6]

Iterative Locate (Streaming)

# Iterate across all documents
for doc_id, pos in mfm.iter_locate(pattern="検索"):
    print(doc_id, pos)
# 4 7
# 5 13
# 3 6

# Iterate within a specific document
for pos in mfm.iter_locate(pattern="検索", doc_id=3):
    print(pos)
# 6
mfm.startswith(prefix="政府は")
mfm.endswith(suffix="注目している。")

Serialization (Pickle Support)

Both FMIndex and MultiFMIndex support Python's pickle protocol, allowing you to save and load pre-built indices efficiently.

The internal data structures are serialized directly in binary format, making deserialization much faster than rebuilding the index from scratch.

Save Index to File

import pickle
from fm_index import FMIndex, MultiFMIndex

# Build and save FMIndex
fm = FMIndex("large genome sequence..." * 10000)
with open("genome.fmindex", "wb") as f:
    pickle.dump(fm, f)

# Build and save MultiFMIndex
mfm = MultiFMIndex(["document1", "document2", ...])
with open("documents.mfmindex", "wb") as f:
    pickle.dump(mfm, f)

Load Index from File

# Load FMIndex
with open("genome.fmindex", "rb") as f:
    fm = pickle.load(f)

# Load MultiFMIndex
with open("documents.mfmindex", "rb") as f:
    mfm = pickle.load(f)

# Use immediately without reconstruction
result = fm.locate("ACGT")

This is particularly useful when:

  • Working with large datasets where index construction is expensive
  • Deploying pre-built indices in production environments
  • Sharing indices across different processes or machines

Development & Testing

Run Tests

pip install -e ".[test]"
cargo test --all --release
pytest

Formating

pip install -e ".[dev]"
cargo fmt --all
cargo clippy --all-targets --all-features
ruff format

Generating Docs

pdoc fm_index \
      --output-directory docs \
      --no-search \
      --docformat markdown \
      --template-directory pdoc_templates

References

Metadata

Release files for fm-index 4.0.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 fm-index 4.0.0
File Size Uploaded
fm_index-4.0.0.tar.gz 70.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fm-index 4.0.0
File
fm_index-4.0.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
fm_index-4.0.0-cp311-abi3-win32.whl CPython 3.11 abi3 Windows x86-32 Details
fm_index-4.0.0-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details
fm_index-4.0.0-cp311-abi3-musllinux_1_2_i686.whl CPython 3.11 abi3 Linux musl 1.2+ x86-32 Details
fm_index-4.0.0-cp311-abi3-musllinux_1_2_armv7l.whl CPython 3.11 abi3 Linux musl 1.2+ ARMv7l Details
fm_index-4.0.0-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details
fm_index-4.0.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details
fm_index-4.0.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.11 abi3 Linux glibc 2.17+ IBM System/390x Details
fm_index-4.0.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.11 abi3 Linux glibc 2.17+ PowerPC 64-le Details
fm_index-4.0.0-cp311-abi3-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-32 Details
fm_index-4.0.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.11 abi3 Linux glibc 2.17+ ARMv7l Details
fm_index-4.0.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
fm_index-4.0.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
fm_index-4.0.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 9.2 MB

Release files / fm_index-4.0.0.tar.gz

Download URL fm_index-4.0.0.tar.gz
Size 70.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c0f126c16eb300b563c639d3221c53203f0cf720218707ef0add1d4ac5881630
BLAKE2b-256 checksum
How to use checksums
d61c7b0249f00c9cd4c5de80ecd2a7b03df19ed51a84a0bd82626998edb39082
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-win_amd64.whl

Download URL fm_index-4.0.0-cp311-abi3-win_amd64.whl
Size 417.5 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
20792a73496ec2e2722d1d440a9867534c4aa4b9458184c891b683ef21c39e9d
BLAKE2b-256 checksum
How to use checksums
d6d8bf24df91206490d49167ac5b9d68c94dd8bd480b0e9c58438df55a6a57e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-win32.whl

Download URL fm_index-4.0.0-cp311-abi3-win32.whl
Size 381.4 kB
Tags CPython 3.11 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
ccd24d19fd70b5b233e3e18eea2655d7db5925d53935b595f5074065a658594d
BLAKE2b-256 checksum
How to use checksums
9e6bd638152711a3515f908fe06735c89af08936b21d03b4224b1dca9c17d7b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL fm_index-4.0.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 832.8 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
e4df9e68b66d32b7c8b687e93ab05f7265f41d68a412bfe0b33957ce3d746fc6
BLAKE2b-256 checksum
How to use checksums
37f5d994f85e4460f87f8ca7d23c82837fbf7952a1aba8c759906cbcc967c029
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-musllinux_1_2_i686.whl

Download URL fm_index-4.0.0-cp311-abi3-musllinux_1_2_i686.whl
Size 878.0 kB
Tags CPython 3.11 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
d2d69dd40ec81ca21cbde8401e11f03d0d41c524f17536a982d8ef1fde71976a
BLAKE2b-256 checksum
How to use checksums
516b6a832b6a95cca9438735d0576ce6f50972d7689690c91039a3dc6807ebae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-musllinux_1_2_armv7l.whl

Download URL fm_index-4.0.0-cp311-abi3-musllinux_1_2_armv7l.whl
Size 891.0 kB
Tags CPython 3.11 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
3be95578cbed2ccf8e937ec5410ea9eac8e4626285ed127e6328d731138d5bda
BLAKE2b-256 checksum
How to use checksums
ff11762a46d845abbd07d88fce91c4e2acb4e95f7c39db3511d8820fb047a6c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL fm_index-4.0.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 781.2 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
c8e9381a6efbef40b54c7b0f0478b737f96dc5d9cfff7fcadb29bd299e05d413
BLAKE2b-256 checksum
How to use checksums
955c9a0115205748de143eb13f8ccac6236f7e67c7852ba095854f5c8fa3d501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fm_index-4.0.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 607.3 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
062c08bac13871d87ff0770be1201453fd3f17a0b4ae2f35cc8bfcfe577f2063
BLAKE2b-256 checksum
How to use checksums
7e60ffb7bc252d10f63c49290d45d3de35e5ef084d7eda892f72d3f959c99e40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL fm_index-4.0.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 641.9 kB
Tags CPython 3.11 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
f3171c2a613517c0cd318a459295a47029bcf213a04548d82828469546f2a561
BLAKE2b-256 checksum
How to use checksums
8e88aea6df2c89c3cbcad6b6af7d986370cc963702bea49b249544b1c5a31126
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL fm_index-4.0.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 752.4 kB
Tags CPython 3.11 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
8215500f6d14a9fc2cf817f374d1603ff8e1252aee59bfd9131b85d22326f84a
BLAKE2b-256 checksum
How to use checksums
2fe2029638199fb928535113f19385dd8e18ef9112df17b67f8ec3678f51ea5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL fm_index-4.0.0-cp311-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Size 675.5 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-32 abi3
SHA-256 checksum
How to use checksums
fbfbcdaf2b4b216671a6c12f0f19da0b0af93ff1d8cf4da583faf0f62c4c6b2b
BLAKE2b-256 checksum
How to use checksums
ba79d9b460a8e41daf211ab5ced37b2c1a769199fad75df589c8ca95002c90ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL fm_index-4.0.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 616.4 kB
Tags CPython 3.11 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
7a64cdaf5409ab1a49e382cf1777b246d8ee74858e97e7bf319dc09ee48f494f
BLAKE2b-256 checksum
How to use checksums
95c430e0e42ed60b6966b35a493131a3f06302642b0b11f0bc0e412c156fc3dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fm_index-4.0.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 602.8 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
38be80099373ccda2e8e7ad0c8aa9c4576b6fb427eebc33a1b4d63173a0eae03
BLAKE2b-256 checksum
How to use checksums
78c4543a29065dadba1343aa6ba8a7df517bd07f259a9153bcdaedfb93eaaf3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL fm_index-4.0.0-cp311-abi3-macosx_11_0_arm64.whl
Size 539.3 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c391d8eff1b6f92054e3e04a36659c4812c82b3e5263a2201faea7914f3e81af
BLAKE2b-256 checksum
How to use checksums
dcebe49a0633d1a8db418e4f7fe06fcc2727d43dd6017dc2275b47604b32ed51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log

Release files / fm_index-4.0.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL fm_index-4.0.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 544.5 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d35293bd298cd0844de12cafbe9c9aa1114661b17d4c7d9179b59dac2438462a
BLAKE2b-256 checksum
How to use checksums
24fb5a1954ff8293480da58823853840c6fb890e04fb591c161613c0f263dd13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 13, 2026.

Transparency log
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