Registry / data / fuzzyset2

fuzzyset2

JSON →
library0.2.5pypypi✓ verified 87d ago

fuzzyset2 is a Python library that provides a data structure for performing fuzzy string matching, akin to full-text search. It helps identify likely misspellings and approximate string matches by breaking strings into n-grams and using a reverse index and cosine similarity. It is a maintained fork of the original 'fuzzyset' package, addressing past installation and maintenance issues. The current version is 0.2.5, and it appears to be actively maintained with recent releases.

pip install fuzzyset2
INSTALL
IMPORT
SIG · FUZZYSET2
F
fuzzyset2
datapythonv0.2.5
Install
2.4s avg
Import
33ms
Disk
28MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.033s · 30MB
28MB installed
● package 28MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FuzzySet
from fuzzyset import FuzzySet
cFuzzySet
from cfuzzyset import cFuzzySet
from fuzzyset import cFuzzySet
cFuzzySet is a Cython-optimized version and must be imported from 'cfuzzyset' if available, otherwise fallback to Python implementation.

Initialize a FuzzySet and add strings. Use the .get() method to find approximate matches for a query string. The result is a list of (score, matched_value) tuples, where the score indicates similarity between 0 and 1.

from fuzzyset import FuzzySet # Initialize with an iterable or add strings later a = FuzzySet(['apple', 'banana', 'orange']) # Add a new string a.add('aple') # Get fuzzy matches matches = a.get('appel') print(f"Matches for 'appel': {matches}") matches = a.get('banan') print(f"Matches for 'banan': {matches}") # Access by index (if only one perfect match or for illustration) # Note: .get() is generally preferred for fuzzy matching # matches = a['apple'] # This will return a list of (score, value) tuples # print(matches)
Debug
Known issues
breakingUsers migrating from the original `fuzzyset` package might encounter import errors or C compilation issues if they don't explicitly install `fuzzyset2`.
fix
Ensure you are installing `fuzzyset2` (`pip install fuzzyset2`) and updating import statements as necessary. The `fuzzyset2` package aims to resolve these original `fuzzyset` installation problems.
affects: All versions of fuzzyset2 (compared to original fuzzyset)
gotchaFor performance-critical applications, consider using the Cython-optimized `cFuzzySet` if available, which can offer a roughly 15% performance increase.
fix
Implement a conditional import: `try: from cfuzzyset import cFuzzySet as FuzzySet; except ImportError: from fuzzyset import FuzzySet`. Ensure Cython is installed (`pip install Cython`) and your environment can compile C extensions.
affects: All versions
gotchafuzzyset2 normalizes input strings by removing non-word characters (except spaces and commas) and converting them to lowercase before processing. This can lead to unexpected matches if case-sensitivity or special characters are critical for your matching logic.
fix
Be aware of this inherent normalization. If you require case-sensitive or special-character-sensitive matching, you may need to preprocess your strings or choose a different fuzzy matching library.
affects: All versions
gotchaAdding a large number of words to a FuzzySet sequentially can be slow. Parallelization is not directly supported by the FuzzySet object itself.
fix
For very large datasets, consider initializing the FuzzySet with an iterable (e.g., `FuzzySet(my_large_list_of_words)`) to leverage internal optimizations. For extreme cases, multiprocessing could be used to add chunks of words to separate FuzzySet instances, which are then queried individually or combined if feasible, though the latter might be complex.
affects: All versions
Errors
Common errors & fixes
error: command 'gcc' failed with exit status 1 (or similar C compilation error referencing `cfuzzyset.c`)
Attempting to install the original `fuzzyset` package which has known issues with its Cython compilation on various systems or missing `cfuzzyset.c` in the distribution.
fix
Use the maintained fork: `pip install fuzzyset2`. This version aims to resolve the underlying C compilation problems and provides wheels.
ImportError: cannot import name 'cFuzzySet' from 'fuzzyset'
Trying to import `cFuzzySet` directly from `fuzzyset` when the Cython-optimized version `cfuzzyset` is not compiled or available in the environment.
fix
Use the recommended conditional import pattern: `try: from cfuzzyset import cFuzzySet as FuzzySet; except ImportError: from fuzzyset import FuzzySet`. Ensure Cython is installed (`pip install Cython`) for `cfuzzyset` to be built.
fuzzy_set.get('query') returns an empty list or unexpected low-scoring results for visually similar strings.
This can happen if the `gram_size_lower` or `gram_size_upper` parameters are too restrictive for the length of your strings, or if `use_levenshtein` is set to `False` causing less accurate scoring for transpositions/minor edits.
fix
When initializing `FuzzySet`, experiment with `gram_size_lower` and `gram_size_upper` (defaults are 2 and 3). Ensure `use_levenshtein=True` (default) for better accuracy with common misspellings. Also, check the input strings for leading/trailing whitespace or unexpected characters that might be removed during normalization.
Upgrade
Version history
0.2.5latest on PyPI · released Oct 21, 2024
Audit
Dependencies
python-levenshteinrequiredUsed for Levenshtein distance calculations in match scoring, significantly improving accuracy.
Agent activity
6 hits · last 30 days
node
6
Resources
fuzzyset2 — pip install fuzzyset2 · libregistry