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

Prefix / Suffix Search

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 3.0.2

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 3.0.2
File Size Uploaded
fm_index-3.0.2.tar.gz 74.5 kB Details

Built distributions (wheels)

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

Total release size: 9.3 MB

Release files / fm_index-3.0.2.tar.gz

Download URL fm_index-3.0.2.tar.gz
Size 74.5 kB
Tags Source
SHA-256 checksum
How to use checksums
805d0b553b95e2967b59d283e436e4e4043679354c90c564da99064c1a6fa1bf
BLAKE2b-256 checksum
How to use checksums
cff036e36a0e0e65c96cdd7ef56f3595633cd80eee8280b789e8bd6fbf657294
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-win_amd64.whl

Download URL fm_index-3.0.2-cp39-abi3-win_amd64.whl
Size 426.0 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e061998d8d391b593b44b074896833fc06df79e4b4842d957ab492ed5cdd2cd8
BLAKE2b-256 checksum
How to use checksums
5413d81f33597135a67b0f1b19eb6747e86777f13445b138f58333d58aefae8c
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-win32.whl

Download URL fm_index-3.0.2-cp39-abi3-win32.whl
Size 384.7 kB
Tags CPython 3.9 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
622bedf8d0cfaa5b22c185b1ecd3249425a02a9a66c970df309e71a19cf55ca7
BLAKE2b-256 checksum
How to use checksums
370fd0e4ad00cb79ae88ff9b58f04cb7962339cb6210c572aeb43c1977c97455
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL fm_index-3.0.2-cp39-abi3-musllinux_1_2_x86_64.whl
Size 830.3 kB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
0d3f2c46783d9a472fe8a60effb2cb0ac4710ecf2e1df508b9167f32c84fc0db
BLAKE2b-256 checksum
How to use checksums
f9f7770403ae0284cc4c01e2e25e127814344ddfb1db80ac105e06bd6113ada5
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-musllinux_1_2_i686.whl

Download URL fm_index-3.0.2-cp39-abi3-musllinux_1_2_i686.whl
Size 883.2 kB
Tags CPython 3.9 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
74f6b08ed775819da1972696ee4f0ea3925cd62f7d927cffcd682b2a0c7e41b2
BLAKE2b-256 checksum
How to use checksums
9b83d1ba9178d8400f10fd7b8ade157251335c41364dfa9098117307f9b5b859
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-musllinux_1_2_armv7l.whl

Download URL fm_index-3.0.2-cp39-abi3-musllinux_1_2_armv7l.whl
Size 898.8 kB
Tags CPython 3.9 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
929fb87384fbc1c79aab642ef1cea5c5e82bd17811d9444225c8503a97c79f5e
BLAKE2b-256 checksum
How to use checksums
adafdb3460cac3c32b4b78db0148ec89fd60f1d00cb535b3620e5910c69d1f8c
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL fm_index-3.0.2-cp39-abi3-musllinux_1_2_aarch64.whl
Size 787.6 kB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
2da4dacf7ebbfb53543bd64047e6cfea679c9036786a58b65a505a83c04810bc
BLAKE2b-256 checksum
How to use checksums
96a24f0c68fe394e7798a9f9c5350df981b9d7c54899dcafb2250d57f40efad1
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fm_index-3.0.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 602.3 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
99b39d9d379a62ade529ce252eb7fd8f7731e21e54f4e58dd536413690c65f82
BLAKE2b-256 checksum
How to use checksums
0865c5a6412c6651763491629caf771fb44384f4924529a3e626b3d3b4938617
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL fm_index-3.0.2-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 644.8 kB
Tags CPython 3.9 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
6172ea8fa87fbbc0829ff2fcecb1aa16d2e7c95393397abbbc0b683e6a4a124c
BLAKE2b-256 checksum
How to use checksums
f35f04fea885b547a0b035b9f7e79917c567767599b724b818e253c8681669c9
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL fm_index-3.0.2-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 755.1 kB
Tags CPython 3.9 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
6e9f1e34522ce386b5f964373fb578c06ae7d979533b6cf38f80dc3c0b8d9bad
BLAKE2b-256 checksum
How to use checksums
ab56da9c4d7fef2e22cccafd9131be162b09c1668c3262161d71147dcacfe096
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL fm_index-3.0.2-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Size 680.1 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-32 abi3
SHA-256 checksum
How to use checksums
79b327e3868cccd193ed204a63997590a8c68754695dce85beda1e1adc181957
BLAKE2b-256 checksum
How to use checksums
c126a30ad3e12a2754c2fb839d2131ea100c005bc27dd617053f3af69d989c9b
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL fm_index-3.0.2-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 624.1 kB
Tags CPython 3.9 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
397ef80b0a099c4ef240fdc2913ce3d14614c1d2f4be2cfcbe92c8ac2982c7f7
BLAKE2b-256 checksum
How to use checksums
71b4a94ab6829cbeb96868fdc4d2faa1b27e485f38549ab79c6eb87748d65a39
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fm_index-3.0.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 611.1 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2e9795f32ac39f5707fe1a3a59b561f0655c8272967551db0cda2ce34e9bcc65
BLAKE2b-256 checksum
How to use checksums
2e91c88feda0aadcf5cfef5899db13dfaf4149bb877a528e142d5357cc62060f
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-macosx_11_0_arm64.whl

Download URL fm_index-3.0.2-cp39-abi3-macosx_11_0_arm64.whl
Size 538.8 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a5c897bb052e6edc1620d48e181dadd58cf702844c800cd70f2f23c339a4b1f1
BLAKE2b-256 checksum
How to use checksums
3313e38356ddbac9f86729c39bcdcb61cedb49f603fc15dc948f5d229c313978
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 Aug 15, 2026.

Transparency log

Release files / fm_index-3.0.2-cp39-abi3-macosx_10_12_x86_64.whl

Download URL fm_index-3.0.2-cp39-abi3-macosx_10_12_x86_64.whl
Size 550.1 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
cd93e84d1d482f7bfb66eebc90c7456b63c1c16b4ae8928289740d08240b77b0
BLAKE2b-256 checksum
How to use checksums
1c0865a8c43004853f20c2a68867e7f74f8e302cf49499bfe09541025ffa6cd4
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 Aug 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.0.2 This release

15 release files

1.2.1

83 release files

1.2.0

84 release files

1.1.1

84 release files

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