TheFuzz
Fuzzy string matching like a boss. It uses Levenshtein Distance to calculate the differences between sequences in a simple-to-use package.
Requirements
Python 3.8 or higher
For testing
pycodestyle
hypothesis
pytest
Installation
Using pip via PyPI
pip install thefuzz
Using pip via GitHub
pip install git+git://github.com/seatgeek/thefuzz.git@0.19.0#egg=thefuzz
Adding to your requirements.txt file (run pip install -r requirements.txt afterwards)
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
Usage
>>> from thefuzz import fuzz
>>> from thefuzz import process
Simple Ratio
>>> fuzz.ratio("this is a test", "this is a test!")
97
Partial Ratio
>>> fuzz.partial_ratio("this is a test", "this is a test!")
100
Token Sort Ratio
>>> fuzz.ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear")
91
>>> fuzz.token_sort_ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear")
100
Token Set Ratio
>>> fuzz.token_sort_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear")
84
>>> fuzz.token_set_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear")
100
Partial Token Sort Ratio
>>> fuzz.token_sort_ratio("fuzzy was a bear", "wuzzy fuzzy was a bear")
84
>>> fuzz.partial_token_sort_ratio("fuzzy was a bear", "wuzzy fuzzy was a bear")
100
Process
>>> choices = ["Atlanta Falcons", "New York Jets", "New York Giants", "Dallas Cowboys"]
>>> process.extract("new york jets", choices, limit=2)
[('New York Jets', 100), ('New York Giants', 78)]
>>> process.extractOne("cowboys", choices)
("Dallas Cowboys", 90)
You can also pass additional parameters to extractOne method to make it use a specific scorer. A typical use case is to match file paths:
>>> process.extractOne("System of a down - Hypnotize - Heroin", songs)
('/music/library/good/System of a Down/2005 - Hypnotize/01 - Attack.mp3', 86)
>>> process.extractOne("System of a down - Hypnotize - Heroin", songs, scorer=fuzz.token_sort_ratio)
("/music/library/good/System of a Down/2005 - Hypnotize/10 - She's Like Heroin.mp3", 61)
Metadata
Release files for thefuzz 0.22.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| thefuzz-0.22.1.tar.gz | 20.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| thefuzz-0.22.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.2 kB
Release files / thefuzz-0.22.1.tar.gz
| Download URL | thefuzz-0.22.1.tar.gz |
|---|---|
| Size | 20.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7138039a7ecf540da323792d8592ef9902b1d79eb78c147d4f20664de79f3680
|
|
BLAKE2b-256 checksum How to use checksums |
814bd3eb25831590d6d7d38c2f2e3561d3ba41d490dc89cd91d9e65e7c812508
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / thefuzz-0.22.1-py3-none-any.whl
| Download URL | thefuzz-0.22.1-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59729b33556850b90e1093c4cf9e618af6f2e4c985df193fdf3c5b5cf02ca481
|
|
BLAKE2b-256 checksum How to use checksums |
824f1695e70ceb3604f19eda9908e289c687ea81c4fecef4d90a9d1d0f2f7ae9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for thefuzz 0.22.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.