Skip to main content

Fast fuzzy string search using finite state transducers

Project description

FuzzyFST

Fast fuzzy string search using finite state transducers. Sub-millisecond approximate string matching on dictionaries with hundreds of thousands of words.

Install

pip install fuzzyfst

Prebuilt wheels for Python 3.10-3.13 on Windows, macOS (Intel + ARM), and Linux.

Quick start

import fuzzyfst

# Build an index from a word list.
words = ["algorithm", "algorism", "algebra", "cat", "car", "cart", "card"]
fuzzyfst.build("index.fst", words)

# Open the index (zero-copy memory-mapped).
fst = fuzzyfst.Fst.open("index.fst")

# Exact lookup.
fst.contains("algorithm")   # True
fst.contains("algoritm")    # False

# Fuzzy search — find all words within edit distance 1.
results = fst.fuzzy_search("algoritm", 1)
# [("algorism", 1), ("algorithm", 1)]

# Higher edit distance finds more results.
results = fst.fuzzy_search("car", 2)
# [("car", 0), ("card", 1), ("cart", 1), ("cat", 1)]

Use cases

  • Spell checking: look up a word with contains(), suggest corrections with fuzzy_search().
  • Autocomplete with typo tolerance: match user input against a dictionary even when misspelled.
  • Search-as-you-type: find candidate matches in sub-millisecond time for interactive UIs.
  • Data deduplication: find near-duplicate strings in datasets.
  • Bioinformatics: approximate matching on sequence databases.

API

fuzzyfst.build(output_path, words, sort_input=True)

Build an FST index file from a list of words.

  • output_path — path to write the .fst file.
  • words — list of strings.
  • sort_input — if True (default), sorts the input automatically.

fuzzyfst.Fst.open(path)

Open a previously-built FST file. The file is memory-mapped for zero-copy access.

fst.contains(key) -> bool

Exact membership test. O(key length), independent of dictionary size.

fst.fuzzy_search(query, max_distance=1) -> list[tuple[str, int]]

Find all words within max_distance Levenshtein edits of query. Returns a list of (word, distance) tuples.

  • Max query length: 64 characters.
  • Recommended max distance: 1-3. Distance 4+ works but produces large result sets.

fst.num_nodes -> int

Number of nodes in the FST (for diagnostics).

Performance

Benchmarked on a 370,105-word English dictionary (Intel i5-9600K, GCC 13.2, -O3):

Distance Avg latency Avg results
d=1 50 us 1.9
d=2 415 us 39.2
d=3 2,040 us 471.9

Index size: 1.9 MB for 370K words. Build time: 93 ms.

How it works

FuzzyFST stores the dictionary in a minimized acyclic finite state transducer (FST). Fuzzy queries intersect a bit-parallel Levenshtein NFA with the FST using iterative DFS. Each FST node is processed in O(1) using Myers' algorithm with 64-bit bitvectors. Subtrees that cannot produce matches are pruned early.

See INTERNALS.md for algorithm details.

C++ API

FuzzyFST is a C++23 library with Python bindings. The full C++ API and build instructions are at github.com/markymn/fuzzyfst.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fuzzyfst-0.1.4.tar.gz (55.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fuzzyfst-0.1.4-cp313-cp313-win_amd64.whl (64.1 kB view details)

Uploaded CPython 3.13Windows x86-64

fuzzyfst-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (72.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fuzzyfst-0.1.4-cp313-cp313-macosx_10_14_universal2.whl (116.4 kB view details)

Uploaded CPython 3.13macOS 10.14+ universal2 (ARM64, x86-64)

fuzzyfst-0.1.4-cp312-cp312-win_amd64.whl (64.2 kB view details)

Uploaded CPython 3.12Windows x86-64

fuzzyfst-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (72.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fuzzyfst-0.1.4-cp312-cp312-macosx_10_14_universal2.whl (116.5 kB view details)

Uploaded CPython 3.12macOS 10.14+ universal2 (ARM64, x86-64)

fuzzyfst-0.1.4-cp311-cp311-win_amd64.whl (65.1 kB view details)

Uploaded CPython 3.11Windows x86-64

fuzzyfst-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (73.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fuzzyfst-0.1.4-cp311-cp311-macosx_10_14_universal2.whl (118.5 kB view details)

Uploaded CPython 3.11macOS 10.14+ universal2 (ARM64, x86-64)

fuzzyfst-0.1.4-cp310-cp310-win_amd64.whl (65.3 kB view details)

Uploaded CPython 3.10Windows x86-64

fuzzyfst-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (73.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

fuzzyfst-0.1.4-cp310-cp310-macosx_10_14_universal2.whl (118.8 kB view details)

Uploaded CPython 3.10macOS 10.14+ universal2 (ARM64, x86-64)

File details

Details for the file fuzzyfst-0.1.4.tar.gz.

File metadata

  • Download URL: fuzzyfst-0.1.4.tar.gz
  • Upload date:
  • Size: 55.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fuzzyfst-0.1.4.tar.gz
Algorithm Hash digest
SHA256 a25295265cdd09841781823c4db86b5ee28390ce69981f0155770966afdfd9ff
MD5 70a9565b6f0741fea2baa3fd42635c3b
BLAKE2b-256 94dbaec27dfab04a7110d393afe80f5441253d30653a6ff520f6b43c003ea48a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4.tar.gz:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.1.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 64.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fuzzyfst-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 70ae90b6c73412bff0654c5eeb091937abbad08f6009e4247a39b50d6c76a859
MD5 c4ae03d23ad5fd761e94538a9d7f34a7
BLAKE2b-256 646dddefc0560518db49997048b8ee65cda61153b32ba56d27ba2f1e14b276d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 68ec5f1d2855360b0842c70c5d1fc4f069ab39252f751b53541d1197fe4d2bd0
MD5 be265429a800dae30bde2b36e9620ae8
BLAKE2b-256 4ebbed933f049b9118ab7e9b079c486811f6a8f4ab1ac1b23cfb131b988d0e46

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp313-cp313-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp313-cp313-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 2c1355426af4946762b2dc45e34a57bf119c19facd4cb729c15558ea007f2f66
MD5 74bf1ba43b11a402985c17750dded1be
BLAKE2b-256 de2a5b568923b100b3d23f84c84d6fecb28b2ae42b1bc3ad5ba9b025b21eb64d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp313-cp313-macosx_10_14_universal2.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.1.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 64.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fuzzyfst-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 62615de649d2b9963c2de1c1b93f31c5a1b7eaeb37d952f4ffa91cb7fd576fe4
MD5 2ebd8d1506188fb0aa9a4137941a8f03
BLAKE2b-256 4694e01153bec4b0e90f6d21dc159e51a9a2d4b7529e704a09d2637633e4c1cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 90c697896f60d1726314c62314eb9e7ce9492c8eaa10135b5219243e2755e90b
MD5 5e8ba38232a6561f43c71b12602726ec
BLAKE2b-256 853014885eb6bb2a1c941e089c354c2ecfc791baed7a486d5fc1c8867ee5d6a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp312-cp312-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp312-cp312-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 e496465be08655d3c564b1fd9256c05bd04ea46484131a8c675b6dc9512849f2
MD5 89bb913f5f5b41e4c83bab3c88f97bce
BLAKE2b-256 b18aaab6c8607b547dc9cd4f6eec52c263c305da15f828ad4f904f285a15e590

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp312-cp312-macosx_10_14_universal2.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.1.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 65.1 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fuzzyfst-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fdb683cb3cbbd61887b67d4150cfed58dd672f26f3d0349ae02dd95ad8296467
MD5 4ec11024927110b71f7e01a2348b8267
BLAKE2b-256 89315b51495f2fe1ca2087008e963c97545f8049dd6d2197b3b14926a84602ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dba1f3c8a3b7b5bac1b471b05dcc7c8c249f623d6e941d5800b572b17821b341
MD5 3be819c22f11d81dd8cee2fb8eab1ac1
BLAKE2b-256 7ae0f59cebc3f2162d2c8684c902275df48eee0a1d1a30fd01368c2a614710ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp311-cp311-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp311-cp311-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 2c2bdea514a1b35e77d28b130d6ae3506c91d2cbc76d9b2ce007d0b06e49d074
MD5 a58e422e42826c13a3737942b834301c
BLAKE2b-256 1c4a07932a651e9721927e8a9a3dc6356b9a45ca505b62d328fd3755dc206919

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp311-cp311-macosx_10_14_universal2.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.1.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 65.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fuzzyfst-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1d963e5eee8eb1b2dcf7e64437e9ef926754e964e8d1e10cbbf35431b54157bb
MD5 e32ed97f9b6279810c48cd2997dec883
BLAKE2b-256 947b00180384e5a82c61f68e7cdbd35d0c883a35743c779ee40a52be10d9ae36

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp310-cp310-win_amd64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 551007f9d1932d2a0999a2e2f44841a792a8cba638abc78d358883a81442a5cb
MD5 fec7fa23cf60f482b78eb076b1073c17
BLAKE2b-256 abaf1cd3c2c01495372ffe9165d17c525142e619ad0dfd191449c7d9254f1abf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fuzzyfst-0.1.4-cp310-cp310-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.1.4-cp310-cp310-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 8fc5039aa3300490478783abac6dfab0eb4ff91a6ec0ab6b61fbb6c1b3f5d597
MD5 52254fc46b039c2dea89fd71d2a6ba83
BLAKE2b-256 b57ac6b16e94a8247f2ece7b1cc12d42510b19458711a276988841a6475613b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.1.4-cp310-cp310-macosx_10_14_universal2.whl:

Publisher: publish.yml on markymn/fuzzyfst

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page