FuzzyTrie
FuzzyTrie is a lightweight, fast, and dependency-free fuzzy search library for Python, written in Rust. It performs efficient string matching and correction using a Levenshtein automaton, as described in this paper
Usage
from fuzzytrie import FuzzyTrie
t = FuzzyTrie()
# Initialize automatons for edit distances of 1 and 2
t.init_automaton(d=1)
t.init_automaton(d=2)
for w in ["lavanshtain", "levanshtain", "levenshtain"]:
t.add(w)
# Perform fuzzy searches with different maximum distances
print(t.search(query="levenshtein", d=2))
# Returns list of distances between query and element, and elements
# >> [(2, 'levanshtain'), (1, 'levenshtain')]
print(t.search(query="levenshtein", d=1))
# >> [(1, 'levenshtain')]
Limitations
- The maximum supported Levenshtein distance is 15.
- Automaton initialization time grows quickly with larger distances.
For example:
- d = 1–3: initialization completes in a fraction of a second.
- d = 4: initialization takes about 14 seconds.
Benchmarks
Benchmarks were run on a dataset of ~460k words with 500 sample queries for each distance. Results were compared against a brute-force implementation (Levenshtein distance in C from rapidfuzz/Levenshtein)
| Distance | Automaton init time (s) | Avg. FuzzyTrie search (s) | Avg. brute force search (s) | Speedup |
|---|---|---|---|---|
| 1 | ~3.29e-05 | ~0.00046 | ~0.14 | 306x |
| 2 | ~0.000608 | ~0.00167 | ~0.14 | 84x |
| 3 | ~0.053419 | ~0.00502 | ~0.14 | 27x |
Theory of operation
Brief explaination of how this works internally can be found here
Metadata
Release files for fuzzytrie 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fuzzytrie-0.3.0.tar.gz | 6.8 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| fuzzytrie-0.3.0-cp313-cp313-macosx_11_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 11.0+ ARM64 | Details |
| fuzzytrie-0.3.0-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
| fuzzytrie-0.3.0-cp311-cp311-macosx_11_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 11.0+ ARM64 | Details |
| fuzzytrie-0.3.0-cp310-cp310-macosx_11_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 11.0+ ARM64 | Details |
Total release size: 876.5 kB
Release files / fuzzytrie-0.3.0.tar.gz
| Download URL | fuzzytrie-0.3.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7503432b532cb454f973be0b8210de069b5ac5d38e2558281dfccf4d03423264
|
|
BLAKE2b-256 checksum How to use checksums |
9e6828db0b2bcbc22045d3481758b33150b78b5016a7a2b470dabce76ad1c174
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / fuzzytrie-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | fuzzytrie-0.3.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 216.3 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ece57dcdd54ff3e39ded66e59c721e10494d3a1b0178ee59659678af48b2663c
|
|
BLAKE2b-256 checksum How to use checksums |
ae099473a0cb93f8f87e53785519dcbee48dd9f33187f65a210d912c61e85411
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / fuzzytrie-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | fuzzytrie-0.3.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 216.3 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4c1bba0c1d81f54929032e0c054f0e541649fb7817de612c246855d23bb9e4d1
|
|
BLAKE2b-256 checksum How to use checksums |
67647c9b3b3e022011be689c89af79d3afb0ecc992baab58448db66ffab34f53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / fuzzytrie-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | fuzzytrie-0.3.0-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 218.6 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5d025cd738ce541a814e545ef41a65b82c00d54c56f8978640715f367a8f358a
|
|
BLAKE2b-256 checksum How to use checksums |
452517a6b79adbda3b8582acd5efb803d2dc9d2b2aeef9dfc2b0fdd4468d0893
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|
Release files / fuzzytrie-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | fuzzytrie-0.3.0-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 218.6 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3b83f76325673b75f3175682d770dc84998894d6513d38ba897527d449e38b77
|
|
BLAKE2b-256 checksum How to use checksums |
88cc7ffc90b9aee48868f8ad836b1b5c4292fabf98c8893d947c519602107eee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.4
|