Skip to main content

Character trigram fuzzy set.

Project description

Character trigram fuzzy set implementation providing cosine similarity-based fuzzy matching.

This library does that one thing on iterables of strings. Any beyond that–Levenshtein distance, scoring, bigram fallback, etc.–is left as an exercise to the reader.


import os.path
from timeit import timeit
import requests

# Retrieve a file containing around 470,000 English words
url = ''
r = requests.get(url, stream=True)
words_path = os.path.expanduser('~/words.txt')
if not os.path.isfile(words_path):
    with open(words_path, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:

# Usage
import charactertrigramfuzzyset as ctfs
items = [line.rstrip() for line in open(words_path, 'r')]
fs = ctfs.CharacterTrigramFuzzySet(items)

# Profiling, generally around 10-20 ms per call on my machine
timeit("fs.get('bryan')", setup='''
import charactertrigramfuzzyset as ctfs
items = [line.rstrip() for line in open('{words_path}', 'r')]
fs = ctfs.CharacterTrigramFuzzySet(items)
'''.format(words_path=words_path), number=1000)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for charactertrigramfuzzyset, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size charactertrigramfuzzyset-0.0.2-py3-none-any.whl (2.8 kB) File type Wheel Python version 3.6 Upload date Hashes View
Filename, size charactertrigramfuzzyset-0.0.2.tar.gz (3.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page