Skip to main content

Python wrapper for junegunn's fuzzyfinder (fzf)

Project description

Yapy-Fuzz

Yet another python wrapper for junegunn's fzf pronunced yaa-pee fuzz with handlers for python lists, sqlite3 and postgres

Why create another wrapper lib?

I wanted a quick way to do fuzzy search on any data source from text files to databases and I couldn't find a single tool that has support for various different inputs/sources for fzf.

Requirements

  • Python 3.6+
  • fzf
  • sqlite3
  • pandas (for postgres support)

Note: fzf and sqlite3 must be installed and available on PATH.

Installation

pip install yapy-fuzz

Usage

>>> from yapyfuzz.core import Fuzzy
>>> fzf = Fuzzy()

If fzf is not available on PATH, you can specify a location

>>> fzf = Fuzzy(exec_path="/path/to/fzf")

Initiate a handler depending on your requirements, for e.g., python lists.

>>> from yapyfuzz.core import ListHandler
>>> list_handler = ListHandler()
>>> list_handler.reader(range(0,10))

>>> fzf = Fuzzy(list_handler)
>>> fzf.get_selection(list_handler)

SQLite DB Handler

>>> from yapyfuzz.core import SQLiteHandler
>>> name = f"{root_dir}/yapy/fuzzy.db"
>>> query = "select * from albums"
>>> db_handler = SQLiteHandler()
>>> db_handler.reader(name, query)

>>> fp = Fuzzy(db_handler)
>>> fp.get_selection()

Postgres DB Handler

>>> from yapyfuzz.core import PostgresHandler

>>> db_settings = {
    "user":"postgres",
    "password":"postgres",
    "host":"localhost",
    "port":"5432",
    "dbname":"dellstore",
}

>>> pg_handler = PostgresHandler()

>>> pg_handler.reader(query="select * from categories", **db_settings)
>>> pg_handler.reader(query="select * from inventory", **db_settings)

>>> fp = Fuzzy(pg_handler)
>>> fp.get_selection()

You can pass additional arguments to fzf as a second argument

>>> fzf.prompt(range(0,10), '--multi --cycle')

Input items are written to a temporary file which is then passed to fzf. The items are delimited with \n by default.

License

MIT

Todo

  • Add support for postgres db
  • CLI table explorer tool to navigate db and tables

CHANGES

2023.03.21: Initial release

Project details


Download files

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

Source Distribution

yapy-fuzz-0.1.0.tar.gz (342.7 kB view details)

Uploaded Source

Built Distribution

yapy_fuzz-0.1.0-py3-none-any.whl (344.2 kB view details)

Uploaded Python 3

File details

Details for the file yapy-fuzz-0.1.0.tar.gz.

File metadata

  • Download URL: yapy-fuzz-0.1.0.tar.gz
  • Upload date:
  • Size: 342.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for yapy-fuzz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ae42dff18de3f8667e6e28bce3b809aad2b9414ebb2812a9d59b31c98c2dc2fc
MD5 c7559196cbc881b8cd4bb9c70878745a
BLAKE2b-256 6834f31909c61e78c77271af7b3f163634c4e1996dbb786b1657598b4321a377

See more details on using hashes here.

File details

Details for the file yapy_fuzz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: yapy_fuzz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 344.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for yapy_fuzz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8be337c52c0e56d93a1d2727048f58914d15d71aa211036dfa8aa99ace7c0291
MD5 6db0a3eb02a61e3ef70ceeb224536225
BLAKE2b-256 462e8a501ac85571376a1ed9ce06723129a7d24b0bb351f4d4c4dc502491bad5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page