pfzy - Fuzzy String Matching
pfzy is a Python port of the fzy fuzzy string matching algorithm, designed for efficient and accurate fuzzy searching primarily in fuzzy finder applications. It provides asynchronous fuzzy match functions, a fzy scorer, and a substring scorer that can calculate matching scores and provide corresponding indices. The library is currently at version 0.3.4 and supports Python versions `>=3.7,<4.0`. While the last PyPI release was in January 2022, its continued inclusion and updates in distributions like Arch Linux (up to January 2026) suggest it remains an active and relevant tool for specific fuzzy matching needs.
Warnings
- gotcha pfzy strictly requires Python versions between `3.7` and `3.9.x` (specifically tested and uploaded with Python 3.9.5, though PyPI metadata states `<4.0`). Users on Python 3.10+ or Python 3.6 and below may encounter installation or runtime issues.
- gotcha The core `fuzzy_match` function is an `async` function. It must be called using `await` within an `async` context (e.g., inside an `async def` function) or executed directly using `asyncio.run()` in a synchronous script. Failing to do so will result in a `coroutine object` being returned, not the actual results.
- gotcha pfzy is a port of the `fzy` algorithm, primarily designed for interactive fuzzy *finder applications* where matching scores and *indices* are crucial for highlighting. It is not a general-purpose string similarity library like `fuzzywuzzy` or `rapidfuzz` and may behave differently or offer different features than expected if used as a direct replacement for those.
Install
-
pip install pfzy
Imports
- fuzzy_match
from pfzy import fuzzy_match
- FzyScorer
from pfzy import FzyScorer
- SubstringScorer
from pfzy import SubstringScorer
Quickstart
import asyncio
from pfzy import fuzzy_match
async def main():
options = ["apple", "banana", "apricot", "grape"]
query = "ap"
results = await fuzzy_match(query, options)
print(results)
if __name__ == "__main__":
asyncio.run(main())