Skip to content

amjith/fuzzyfinder

Repository files navigation

fuzzyfinder

GitHub Badge ReadTheDocs Badge

fuzzyfinder is a fuzzy finder implemented in Python. It matches partial string entries from a list of strings, and works similar to the fuzzy finder in SublimeText and Vim's Ctrl-P plugin.

https://raw.githubusercontent.com/amjith/fuzzyfinder/master/screenshots/pgcli-fuzzy.gif

Some notable features of fuzzyfinder are:

  • Simple, easy to understand code.
  • No external dependencies, just the Python standard library.

An in-depth overview of the algorithm behind fuzzyfinder is available in this blog post.

Quick Start

Installation

$ pip install fuzzyfinder

Usage

>>> from fuzzyfinder import fuzzyfinder

>>> suggestions = fuzzyfinder('abc', ['acb', 'defabca', 'abcd', 'aagbec', 'xyz', 'qux'])
>>> list(suggestions)
['abcd', 'defabca', 'aagbec']

>>> # Use a user-defined function to obtain the string against which fuzzy matching is done
>>> collection = ['aa bbb', 'aca xyz', 'qx ala', 'xza az', 'bc aa', 'xy abca']
>>> suggestions = fuzzyfinder('aa', collection, accessor=lambda x: x.split()[1])
>>> list(suggestions)
['bc aa', 'qx ala', 'xy abca']

>>> # With the appropriate accessor you can pass non-string collections, too
>>> collection = [1234, 5678, 7537, 888, 57, 77]
>>> suggestions = fuzzyfinder('57', collection, accessor=str)
>>> list(suggestions)
[57, 5678, 7537]

>>> # Make filtering case-sensitive
>>> collection = ['bAB', 'aaB', 'Aab', 'xyz', 'adb', 'aAb']
>>> suggestions = fuzzyfinder('Ab', collection, ignore_case=False)
>>> list(suggestions)
['aAb', 'Aab']

>>> # By default, elements with matches of same rank are sorted alpha-numerically
>>> suggestions = fuzzyfinder('aa', ['aac', 'aaa', 'aab', 'xyz', 'ada'])
>>> list(suggestions)
['aaa', 'aab', 'aac', 'ada']

>>> # Preserve original order of elements if matches have same rank
>>> suggestions = fuzzyfinder('aa', ['aac', 'aaa', 'aab', 'xyz', 'ada'], sort_results=False)
>>> list(suggestions)
['aac', 'aaa', 'aab', 'ada']

Similar Projects

About

Fuzzy Finder implemented in Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •