fuzzy_types Reference¶
Config¶
-
fuzzy_types.configuration.merge_config(user, default)[source]¶ Merges a user configuration with the default one.
-
fuzzy_types.configuration.get_config(name, config_file=None, allow_user=True, user_path=None, config_envvar=None, merge_mode='update')[source]¶ Returns a configuration dictionary.
The configuration dictionary is created by merging the default configuration file that is part of the library (normally in
etc/<name>.yml) with a user configuration file. The path to the user configuration file can be defined as an environment variable to be passed to this function inconfig_envvaror as a path inuser_path. The environment variable, if exists, always takes precedence.- Parameters
name (str) – The name of the package.
config_file (str) – The path to the configuration file. If
None, defaults toetc/<name>.ymlrelative to the file that calledget_config.allow_user (bool) – If
True, looks for an user configuration file and merges is to the default configuration. Otherwise it returns just the default configuration.user_path (str) – The path to the user configuration file. Defaults to
~/.config/<name>/<name>.yml. Ignored if the file does not exist.config_envvar (str) – The environment variable that contains the path to the user configuration file. Defaults to
<name>_CONFIG_PATH. If the environment variable exists, theuser_pathis ignored.merge_mode (str) – Defines how the default and user dictionaries will be merged. If
update, the user dictionary will be used to update the default configuration. Ifreplace, only the user configuration will be returned.
- Returns
config (dict) – A dictionary containing the configuration.
Fuzzy Types¶
-
class
fuzzy_types.fuzzy.FuzzyList(the_items, use_fuzzy=None, dottable=True)[source]¶ Bases:
fuzzy_types.fuzzy.FuzzyBase,listA dottable python list that uses fuzzywuzzy to select a string item
- Parameters
the_items (list) – A list of items to make fuzzy
use_fuzzy (func) – The function used to perform the fuzzy-matching. Default is
fuzzy_types.utils.get_best_fuzzy().dottable (bool) – If False, turns off dottable attributes. Default is True.
- Returns
A python list with fuzzy items
-
property
choices¶
-
class
fuzzy_types.fuzzy.FuzzyDict(the_dict, use_fuzzy=None, dottable=True)[source]¶ Bases:
fuzzy_types.fuzzy.FuzzyBaseDict,dictA dotable dictionary that uses fuzzywuzzy to select the key.
- Parameters
the_items (dict) – A dictionary of items to make fuzzy
use_fuzzy (func) – The function used to perform the fuzzy-matching. Default is
fuzzy_types.utils.get_best_fuzzy().dottable (bool) – If False, turns off dottable attributes. Default is True.
- Returns
A python dictionary with fuzzy keys
-
class
fuzzy_types.fuzzy.FuzzyOrderedDict(the_dict, use_fuzzy=None, dottable=True)[source]¶ Bases:
fuzzy_types.fuzzy.FuzzyBaseDict,collections.OrderedDictA dotable ordered dictionary that uses fuzzywuzzy to select the key.
- Parameters
the_items (dict) – A dictionary of items to make fuzzy
use_fuzzy (func) – The function used to perform the fuzzy-matching. Default is
fuzzy_types.utils.get_best_fuzzy().dottable (bool) – If False, turns off dottable attributes. Default is True.
- Returns
A python ordered dictionary with fuzzy keys
Helpers¶
-
fuzzy_types.utils.get_best_fuzzy(value, choices, min_score=None, scorer=<function WRatio>, return_score=False)[source]¶ Returns the best match in a list of choices using fuzzywuzzy.
- Parameters
value (str) – A string to match on
choices (list) – A list of string choices to match from
min_score (int) – The score cutoff threshold. The minimum score to consider when matching.
scorer (fuzzywuzzy.Ratio) – The fuzzywuzzy score ratio to use. Default is WRatio.
return_score (bool) – If True, also returns the score value of the match
