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)]

# Compiled DFA — faster traversal, higher startup cost.
results = fst.fuzzy_search("algoritm", 2, algorithm="dfa")

# Damerau-Levenshtein: transpositions count as one edit.
results = fst.fuzzy_search("teh", 1, metric="damerau")
# Finds "the" at distance 1 (transposition).

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, metric="levenshtein", algorithm="bit-parallel") -> list[tuple[str, int]]

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

  • metric"levenshtein" (default) or "damerau" for Damerau-Levenshtein (transpositions count as one edit).
  • algorithm"bit-parallel" (default, zero startup) or "dfa" (compiled DFA, faster traversal but higher startup cost).
  • 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 Lev BitParallel Lev DFA Damerau DFA Avg results
d=1 53 us 17 us 21 us 1.9 / 1.9 / 2.1
d=2 498 us 168 us 209 us 39.2 / 39.2 / 40.9
d=3 2,525 us 924 us 989 us 471.9 / 471.9 / 487.7

DFA modes add one-time compilation cost per (query, distance) pair: Lev DFA 135-1,200 us, Damerau DFA 1,447-13,648 us at d=1-3. 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). Three search modes: bit-parallel (Myers' NFA, zero startup, ~12 bitwise ops per node), Levenshtein DFA (compiled DFA, O(1) table lookup, 3x faster traversal), and Damerau DFA (handles transpositions). 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.2.0.tar.gz (76.4 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.2.0-cp313-cp313-win_amd64.whl (86.5 kB view details)

Uploaded CPython 3.13Windows x86-64

fuzzyfst-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (98.8 kB view details)

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

fuzzyfst-0.2.0-cp313-cp313-macosx_10_14_universal2.whl (160.5 kB view details)

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

fuzzyfst-0.2.0-cp312-cp312-win_amd64.whl (86.6 kB view details)

Uploaded CPython 3.12Windows x86-64

fuzzyfst-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (98.8 kB view details)

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

fuzzyfst-0.2.0-cp312-cp312-macosx_10_14_universal2.whl (160.8 kB view details)

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

fuzzyfst-0.2.0-cp311-cp311-win_amd64.whl (87.4 kB view details)

Uploaded CPython 3.11Windows x86-64

fuzzyfst-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (100.1 kB view details)

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

fuzzyfst-0.2.0-cp311-cp311-macosx_10_14_universal2.whl (162.9 kB view details)

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

fuzzyfst-0.2.0-cp310-cp310-win_amd64.whl (87.6 kB view details)

Uploaded CPython 3.10Windows x86-64

fuzzyfst-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (100.4 kB view details)

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

fuzzyfst-0.2.0-cp310-cp310-macosx_10_14_universal2.whl (163.2 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for fuzzyfst-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3bf60bb9b7c7b8db1b5335dcef21f763eeadd02c5c424840f6fec59f37c12922
MD5 63433aef2c2d8c3ab92cfa886f27285b
BLAKE2b-256 df546f2dcc1300d9a23b877d065b2d1037e75d02172e74593ebcb6217e5a91ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0.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.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 86.5 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.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f88059cd56811a047e1027966b7061574f16ad1f66de64e193670e19a97ec8fa
MD5 bb6acb490c536c6c46fa416a3b686de9
BLAKE2b-256 7102561c6ee042675729941ab8623b86c5c9839a80cfee8657782c98ad5b92f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2a86f498f7f81487d77e893303710c917a01b2629fe4fc30ed4497c68d1751fb
MD5 55ed72876d243378d78379a7ebe96dd8
BLAKE2b-256 2dd805cef6132fe865f53e165ec314e53d802ecfc9c4304a46c00a367b971315

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp313-cp313-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp313-cp313-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 6cbebff060c64788db358a0a4c8b433c5c70e74ce7bd46288622bfc078bca607
MD5 0a8857da1ef383900a195cbedaaeb162
BLAKE2b-256 8b2cbd8ecca428a1d826258195002f39b46beeba3844a7ff0580b1c930ef2af0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 86.6 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.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f2811876efbc9ad4e67b39c0645ee84cfbc82ffe0b2289d7725e1e44cb270e4c
MD5 4cee2e89a197820446993ce112ded074
BLAKE2b-256 fb00dafc2e699980e4dbaa2777f05cad0836a1c64d25da941406d2c40da14dda

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8c72cc5fe963b8dec751e3325960190a0e509a7b55fb313187fa271d3311bde0
MD5 726eab7df06daa52e79c9dd056f464a7
BLAKE2b-256 7787664412b6a236893f1a08509240dd18fe52fb4e485f6ea3cb1db4415f07f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp312-cp312-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp312-cp312-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 f50a49e56ca73c92641b48855fbcb6d3004a917491145e377422fb6a7d7e4910
MD5 e2552ca0b71a8f5f22e90f22a3b3a91d
BLAKE2b-256 51bc90e033de470af5958ee5eb0037f2a5fc4c896137d0e3598d198029521afc

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 87.4 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.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 814c80047958539cd5afbfd625b83d9283155628c1fed3a77411f1800b8bdc65
MD5 0f7431127bd78bb4dd80787593125816
BLAKE2b-256 ef314e1027cd0ad193ab3a8c7d3df7bc8d781cc7f54d516f0de85d54e89362ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cee5fcb4fb5f3842eb66a32f7a6df9c615dcb2288e98bb3687725f3d46e3bd69
MD5 2541bedf18156ba782fbd4959ef10de6
BLAKE2b-256 eff2de37b1cbdae7581d06de7b235bb53ee418a236e86386738f9cfb13b47e83

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp311-cp311-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp311-cp311-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 0223a5a3a224f737d1b086807f50ee61d0e260f8c3a2802d15f58aeef8b0a4f8
MD5 cf3587afbdb4502114fe309e887edc55
BLAKE2b-256 e6655e3963c5c6f38a6d984ab3b011ae1e1bb9f90fcf921e22bd5941ddf7d264

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: fuzzyfst-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 87.6 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.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1b504a779945d6ebcef1a56ca7fa65ee55f65f5467f1c2c88b6f46192d3abfc8
MD5 304599fead263ed1f6b2c9d6dcf2ea10
BLAKE2b-256 6a301431aa82d972c41cb94af20ecfcafb437775fb625efa57c4d5ddf38f822b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 45ec4b4ef46d3b7a28dc966b180eb7910c17c11fe450b78a4580d1b29b99a1df
MD5 e7c59aafb7206cb8bc24d0a54e1a8d84
BLAKE2b-256 c5d7530679387d2e5beafe1c25cbaa9b1211f196318b952cc085d0f0fb6e6d1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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.2.0-cp310-cp310-macosx_10_14_universal2.whl.

File metadata

File hashes

Hashes for fuzzyfst-0.2.0-cp310-cp310-macosx_10_14_universal2.whl
Algorithm Hash digest
SHA256 ca3c8a8c5e04cae7c4b542b18218ede5e6bee1a135e3266235ac9a2cfc5c4f3c
MD5 fa081d8e6bec228c8e7c2403463390b4
BLAKE2b-256 6cd12034eaecbeac2f9b0882018a2e1901ff70f1485e6f75d4e27574eea4243e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuzzyfst-0.2.0-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