thefuzz Documentation

repository·master·Indexed 24 days ago

https://github.com/seatgeek/thefuzz

A Python library for fuzzy string matching using Levenshtein Distance. It provides scoring methods via the thefuzz.fuzz module, including ratio, partial_ratio, token_sort_ratio, and token_set_ratio, as well as tools for extracting the best matches from a list using the thefuzz.process module.

Tokens
472
Snippets
2
Records
5
Agent score
37%

What's inside thefuzz

  1. Install thefuzz from GitHub

    master

    You can install thefuzz directly from the GitHub repository using pip or by cloning the repository manually.

    # Using pip via GitHub
    pip install git+git://github.com/seatgeek/thefuzz.git@0.19.0#egg=thefuzz
    
    # Adding to requirements.txt
    git+ssh://git@github.com/seatgeek/thefuzz.git@0.19.0#egg=thefuzz
    
    # Manually via GIT
    git clone git://github.com/seatgeek/thefuzz.git thefuzz
    cd thefuzz
    python setup.py install
  2. Extract matches from a list using process

    master

    The thefuzz.process module allows you to find the best matches for a string within a list of choices.

    • process.extract(query, choices, limit=None): Returns a list of the top limit matches, where each match is a tuple of (match, score).
    • process.extractOne(query, choices, scorer=None): Returns the single best match as a tuple of (match, score). You can specify a custom scorer from the fuzz module.
  3. Use fuzz scoring methods

    master

    The thefuzz.fuzz module provides several methods to calculate the similarity between two strings using different algorithms based on Levenshtein Distance.

    • fuzz.ratio: Simple ratio comparison.
    • fuzz.partial_ratio: Partial ratio comparison.
    • fuzz.token_sort_ratio: Compares strings after sorting tokens alphabetically.
    • fuzz.token_set_ratio: Compares strings after sorting tokens and removing duplicates.
    • fuzz.partial_token_sort_ratio: A combination of partial ratio and token sort ratio.