### Install humps from source Source: https://humps.readthedocs.io/en/latest/user/install.html Install humps into your site-packages after cloning or downloading the source code. ```bash cd humps $ pipenv install . ``` -------------------------------- ### Install humps with pipenv Source: https://humps.readthedocs.io/en/latest/user/install.html Use this command to install the humps package using pipenv. ```bash $ pipenv install pyhumps ``` -------------------------------- ### Clone humps repository Source: https://humps.readthedocs.io/en/latest/user/install.html Clone the humps public repository from GitHub to get the source code. ```bash $ git clone git://github.com/nficano/humps.git ``` -------------------------------- ### Fix Abbreviations for Decamelization Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Rewrites incorrectly cased acronyms, initialisms, and abbreviations to ensure they are decamelized correctly. For example, 'APIResponse' becomes 'api_response' instead of 'a_p_i_response'. ```python def _fix_abbreviations(string): """ Rewrite incorrectly cased acronyms, initialisms, and abbreviations, allowing them to be decamelized correctly. For example, given the string "APIResponse", this function is responsible for ensuring the output is "api_response" instead of "a_p_i_response". :param string: A string that may contain an incorrectly cased abbreviation. :type string: str :rtype: str :returns: A rewritten string that is safe for decamelization. """ return ACRONYM_RE.sub(lambda m: m.group(0).title(), string) ``` -------------------------------- ### Basic String Conversions with Humps Source: https://humps.readthedocs.io/en/latest/index.html Demonstrates various string format conversions including decamelize, camelize, kebabize, pascalize, and dekebabize. Also shows recursive conversion for lists of dictionaries. ```python >>> import humps >>> humps.decamelize('illWearYourGranddadsClothes') # 'ill_wear_your_granddads_clothes' >>> humps.camelize('i_look_incredible') # 'iLookIncredible' >>> humps.kebabize('i_look_incredible') # 'i-look-incredible' >>> humps.pascalize('im_in_this_big_ass_coat') # 'ImInThisBigAssCoat' >>> humps.decamelize('FROMThatThriftShop') # 'from_that_thrift_shop' >>> humps.decamelize([{'downTheRoad': True}]) # [{'down_the_road': True}] >>> humps.dekebabize('FROM-That-Thrift-Shop') # 'FROM_That_Thrift_Shop' ``` -------------------------------- ### pascalize() Source: https://humps.readthedocs.io/en/latest/genindex.html Converts a string to PascalCase. This function is part of the humps.main module. ```APIDOC ## Function: pascalize() ### Description Converts a string to PascalCase. ### Module humps.main ``` -------------------------------- ### Download humps tarball Source: https://humps.readthedocs.io/en/latest/user/install.html Download the humps source code as a tarball from GitHub. ```bash $ curl -OL https://github.com/nficano/humps/tarball/master ``` -------------------------------- ### kebabize() Source: https://humps.readthedocs.io/en/latest/genindex.html Converts a string to kebab-case. This function is part of the humps.main module. ```APIDOC ## Function: kebabize() ### Description Converts a string to kebab-case. ### Module humps.main ``` -------------------------------- ### Remove Whitespace or Return Empty String for None Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html A helper function that checks if the input is None. If it is, an empty string is returned. Otherwise, the input is converted to a string and all whitespace is removed. ```python def _is_none(_in): """ Determine if the input is None and returns a string with white-space removed :param _in: input :return: an empty sting if _in is None, else the input is returned with white-space removed """ return "" if _in is None else re.sub(r"\s+", "", str(_in)) ``` -------------------------------- ### camelize() Source: https://humps.readthedocs.io/en/latest/genindex.html Converts a string to camelCase. This function is part of the humps.main module. ```APIDOC ## Function: camelize() ### Description Converts a string to camelCase. ### Module humps.main ``` -------------------------------- ### kebabize Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to kebab-case. Handles nested structures recursively. ```APIDOC ## kebabize ### Description Convert a string, dict, or list of dicts to kebab case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - Union[list, dict, str]: kebabized string, dictionary, or list of dictionaries. ``` -------------------------------- ### pascalize Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to PascalCase. Handles nested structures recursively. ```APIDOC ## pascalize ### Description Convert a string, dict, or list of dicts to pascal case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - Union[list, dict, str]: pascalized string, dictionary, or list of dictionaries. ``` -------------------------------- ### is_kebabcase() Source: https://humps.readthedocs.io/en/latest/genindex.html Checks if a string is in kebab-case format. This function is part of the humps.main module. ```APIDOC ## Function: is_kebabcase() ### Description Checks if a string is in kebab-case format. ### Module humps.main ``` -------------------------------- ### is_pascalcase() Source: https://humps.readthedocs.io/en/latest/genindex.html Checks if a string is in PascalCase format. This function is part of the humps.main module. ```APIDOC ## Function: is_pascalcase() ### Description Checks if a string is in PascalCase format. ### Module humps.main ``` -------------------------------- ### is_pascalcase Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Determines if a string, dictionary, or list of dictionaries is in PascalCase. ```APIDOC ## is_pascalcase ### Description Determine if a string, dict, or list of dicts is pascal case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - bool: True/False whether string or iterable is pascal case ``` -------------------------------- ### is_kebabcase Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Determines if a string, dictionary, or list of dictionaries is in kebab-case. ```APIDOC ## is_kebabcase ### Description Determine if a string, dict, or list of dicts is camel case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - bool: True/False whether string or iterable is kebab case ``` -------------------------------- ### Pascalize String, Dict, or List Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to pascal case. Handles nested structures recursively. ```python def pascalize(str_or_iter): """ Convert a string, dict, or list of dicts to pascal case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: Union[list, dict, str] :returns: pascalized string, dictionary, or list of dictionaries. """ if isinstance(str_or_iter, (list, Mapping)): return _process_keys(str_or_iter, pascalize) s = _is_none(str_or_iter) if s.isupper() or s.isnumeric(): return str_or_iter def _replace_fn(match): """ :rtype: str """ return match.group(1)[0].upper() + match.group(1)[1:] s = camelize(PASCAL_RE.sub(_replace_fn, s)) return s[0].upper() + s[1:] if len(s) != 0 else s ``` -------------------------------- ### Kebabize String, Dict, or List Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to kebab case. Handles nested structures recursively. It also attempts to fix abbreviations before conversion. ```python def kebabize(str_or_iter): """ Convert a string, dict, or list of dicts to kebab case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: Union[list, dict, str] :returns: kebabized string, dictionary, or list of dictionaries. """ if isinstance(str_or_iter, (list, Mapping)): return _process_keys(str_or_iter, kebabize) s = _is_none(str_or_iter) if s.isnumeric(): return str_or_iter if not (s.isupper()) and (is_camelcase(s) or is_pascalcase(s)): return ( _separate_words( string=_fix_abbreviations(s), separator="-" ).lower() ) return UNDERSCORE_RE.sub(lambda m: "-" + m.group(0)[-1], s) ``` -------------------------------- ### humps.main.kebabize Source: https://humps.readthedocs.io/en/latest/api.html Converts a string, dictionary, or list of dictionaries to kebab case. This function is useful for creating URL-friendly strings. ```APIDOC ## humps.main.kebabize ### Description Convert a string, dict, or list of dicts to kebab case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type Union[list, dict, str] ### Returns kebabized string, dictionary, or list of dictionaries. ``` -------------------------------- ### dekebabize() Source: https://humps.readthedocs.io/en/latest/genindex.html Converts a kebab-case string to snake_case. This function is part of the humps.main module. ```APIDOC ## Function: dekebabize() ### Description Converts a kebab-case string to snake_case. ### Module humps.main ``` -------------------------------- ### Check if String is Kebab Case Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Determines if a string, dictionary, or list of dictionaries conforms to kebab case convention. Handles nested structures recursively. ```python def is_kebabcase(str_or_iter): """ Determine if a string, dict, or list of dicts is camel case. ``` -------------------------------- ### humps.main.pascalize Source: https://humps.readthedocs.io/en/latest/api.html Converts a string, dictionary, or list of dictionaries to pascal case. This function is useful for converting to PascalCase format. ```APIDOC ## humps.main.pascalize ### Description Convert a string, dict, or list of dicts to pascal case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type Union[list, dict, str] ### Returns pascalized string, dictionary, or list of dictionaries. ``` -------------------------------- ### is_camelcase Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Determines if a string, dictionary, or list of dictionaries is in camelCase. ```APIDOC ## is_camelcase ### Description Determine if a string, dict, or list of dicts is camel case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - bool: True/False whether string or iterable is camel case ``` -------------------------------- ### humps.main.is_kebabcase Source: https://humps.readthedocs.io/en/latest/api.html Determines if a string, dictionary, or list of dictionaries is in kebab case format. Returns a boolean value. ```APIDOC ## humps.main.is_kebabcase ### Description Determine if a string, dict, or list of dicts is camel case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type bool ### Returns True/False whether string or iterable is camel case ``` -------------------------------- ### humps.main.is_pascalcase Source: https://humps.readthedocs.io/en/latest/api.html Determines if a string, dictionary, or list of dictionaries is in pascal case format. Returns a boolean value. ```APIDOC ## humps.main.is_pascalcase ### Description Determine if a string, dict, or list of dicts is pascal case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type bool ### Returns True/False whether string or iterable is pascal case ``` -------------------------------- ### camelize Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to camelCase. Handles nested structures recursively. ```APIDOC ## camelize ### Description Convert a string, dict, or list of dicts to camel case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - Union[list, dict, str]: camelized string, dictionary, or list of dictionaries. ``` -------------------------------- ### is_camelcase() Source: https://humps.readthedocs.io/en/latest/genindex.html Checks if a string is in camelCase format. This function is part of the humps.main module. ```APIDOC ## Function: is_camelcase() ### Description Checks if a string is in camelCase format. ### Module humps.main ``` -------------------------------- ### Check if String is Pascal Case Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Determines if a string, dictionary, or list of dictionaries conforms to pascal case convention. Handles nested structures recursively. ```python def is_pascalcase(str_or_iter): """ Determine if a string, dict, or list of dicts is pascal case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: bool :returns: True/False whether string or iterable is pascal case """ return str_or_iter == pascalize(str_or_iter) ``` -------------------------------- ### depascalize() Source: https://humps.readthedocs.io/en/latest/genindex.html Converts a PascalCase string to snake_case. This function is part of the humps.main module. ```APIDOC ## Function: depascalize() ### Description Converts a PascalCase string to snake_case. ### Module humps.main ``` -------------------------------- ### is_snakecase() Source: https://humps.readthedocs.io/en/latest/genindex.html Checks if a string is in snake_case format. This function is part of the humps.main module. ```APIDOC ## Function: is_snakecase() ### Description Checks if a string is in snake_case format. ### Module humps.main ``` -------------------------------- ### decamelize() Source: https://humps.readthedocs.io/en/latest/genindex.html Converts a camelCase string to snake_case. This function is part of the humps.main module. ```APIDOC ## Function: decamelize() ### Description Converts a camelCase string to snake_case. ### Module humps.main ``` -------------------------------- ### Camelize String, Dict, or List Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to camel case. Handles nested structures recursively. ```python def camelize(str_or_iter): """ Convert a string, dict, or list of dicts to camel case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: Union[list, dict, str] :returns: camelized string, dictionary, or list of dictionaries. """ if isinstance(str_or_iter, (list, Mapping)): return _process_keys(str_or_iter, camelize) s = _is_none(str_or_iter) if s.isupper() or s.isnumeric(): return str_or_iter if len(s) != 0 and not s[:2].isupper(): s = s[0].lower() + s[1:] # For string "hello_world", match will contain # the regex capture group for "_w". return UNDERSCORE_RE.sub(lambda m: m.group(0)[-1].upper(), s) ``` -------------------------------- ### Separate Words by Case Differentiation Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Splits words within a string that are separated by case changes. The individual words are then joined back together using a specified separator, defaulting to an underscore. ```python def _separate_words(string, separator="_"): """ Split words that are separated by case differentiation. :param string: Original string. :param separator: String by which the individual words will be put back together. :returns: New string. """ return separator.join(s for s in SPLIT_RE.split(string) if s) ``` -------------------------------- ### dekebabize Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to snake_case by replacing hyphens with underscores. Handles nested structures recursively. ```APIDOC ## dekebabize ### Description Convert a string, dict, or list of dicts to snake case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - Union[list, dict, str]: snake cased string, dictionary, or list of dictionaries. ``` -------------------------------- ### decamelize Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to snake_case. Handles nested structures recursively. ```APIDOC ## decamelize ### Description Convert a string, dict, or list of dicts to snake case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - Union[list, dict, str]: snake cased string, dictionary, or list of dictionaries. ``` -------------------------------- ### humps.main.dekebabize Source: https://humps.readthedocs.io/en/latest/api.html Converts a string, dictionary, or list of dictionaries to snake case. This function handles kebab-cased strings. ```APIDOC ## humps.main.dekebabize ### Description Convert a string, dict, or list of dicts to snake case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type Union[list, dict, str] ### Returns snake cased string, dictionary, or list of dictionaries. ``` -------------------------------- ### humps.main.is_camelcase Source: https://humps.readthedocs.io/en/latest/api.html Determines if a string, dictionary, or list of dictionaries is in camel case format. Returns a boolean value. ```APIDOC ## humps.main.is_camelcase ### Description Determine if a string, dict, or list of dicts is camel case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type bool ### Returns True/False whether string or iterable is camel case ``` -------------------------------- ### humps.main.decamelize Source: https://humps.readthedocs.io/en/latest/api.html Converts a string, dictionary, or list of dictionaries to snake case. This is commonly used for converting camelCased keys to snake_case. ```APIDOC ## humps.main.decamelize ### Description Convert a string, dict, or list of dicts to snake case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type Union[list, dict, str] ### Returns snake cased string, dictionary, or list of dictionaries. ``` -------------------------------- ### Process Dictionary Keys Recursively Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Recursively processes keys in a string, list, or dictionary using a provided function. For lists, it processes each element. For dictionaries, it applies the function to each key and recursively processes the value. ```python def _process_keys(str_or_iter, fn): if isinstance(str_or_iter, list): return [_process_keys(k, fn) for k in str_or_iter] if isinstance(str_or_iter, Mapping): return {fn(k): _process_keys(v, fn) for k, v in str_or_iter.items()} return str_or_iter ``` -------------------------------- ### humps.main.camelize Source: https://humps.readthedocs.io/en/latest/api.html Converts a string, dictionary, or list of dictionaries to camel case. This function is useful for standardizing key names in data structures. ```APIDOC ## humps.main.camelize ### Description Convert a string, dict, or list of dicts to camel case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type Union[list, dict, str] ### Returns camelized string, dictionary, or list of dictionaries. ``` -------------------------------- ### Check if String is Snake Case Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Determines if a given string, dictionary, or list of dictionaries adheres to snake_case naming conventions. It first checks for kebab-case and non-camelCase patterns before comparing against the decamelized version. ```python def is_snakecase(str_or_iter): """ Determine if a string, dict, or list of dicts is snake case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: bool :returns: True/False whether string or iterable is snake case """ if is_kebabcase(str_or_iter) and not is_camelcase(str_or_iter): return False return str_or_iter == decamelize(str_or_iter) ``` -------------------------------- ### Dekebabize String, Dict, or List Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to snake case by replacing hyphens with underscores. Handles nested structures recursively. ```python def dekebabize(str_or_iter): """ Convert a string, dict, or list of dicts to snake case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: Union[list, dict, str] :returns: snake cased string, dictionary, or list of dictionaries. """ if isinstance(str_or_iter, (list, Mapping)): return _process_keys(str_or_iter, dekebabize) s = _is_none(str_or_iter) if s.isnumeric(): return str_or_iter return s.replace("-", "_") ``` -------------------------------- ### humps.main.is_snakecase Source: https://humps.readthedocs.io/en/latest/api.html Determines if a string, dictionary, or list of dictionaries is in snake case format. Returns a boolean value. ```APIDOC ## humps.main.is_snakecase ### Description Determine if a string, dict, or list of dicts is snake case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type bool ### Returns True/False whether string or iterable is snake case ``` -------------------------------- ### depascalize Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to snake_case. This is an alias for decamelize. ```APIDOC ## depascalize ### Description Convert a string, dict, or list of dicts to snake case. ### Parameters - **str_or_iter** (Union[list, dict, str]): A string or iterable. ### Returns - Union[list, dict, str]: snake cased string, dictionary, or list of dictionaries. ``` -------------------------------- ### Decamelize String, Dict, or List Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to snake case. Handles nested structures recursively. It also attempts to fix abbreviations before conversion. ```python def decamelize(str_or_iter): """ Convert a string, dict, or list of dicts to snake case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: Union[list, dict, str] :returns: snake cased string, dictionary, or list of dictionaries. """ if isinstance(str_or_iter, (list, Mapping)): return _process_keys(str_or_iter, decamelize) s = _is_none(str_or_iter) if s.isupper() or s.isnumeric(): return str_or_iter return _separate_words(_fix_abbreviations(s)).lower() ``` -------------------------------- ### humps.main.depascalize Source: https://humps.readthedocs.io/en/latest/api.html Converts a string, dictionary, or list of dictionaries to snake case. This function is useful for converting PascalCase strings. ```APIDOC ## humps.main.depascalize ### Description Convert a string, dict, or list of dicts to snake case. ### Parameters #### Path Parameters - **str_or_iter** (Union[list, dict, str]) - Required - A string or iterable. ### Return Type Union[list, dict, str] ### Returns snake cased string, dictionary, or list of dictionaries. ``` -------------------------------- ### Check if String is Camel Case Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Determines if a string, dictionary, or list of dictionaries conforms to camel case convention. Handles nested structures recursively. ```python def is_camelcase(str_or_iter): """ Determine if a string, dict, or list of dicts is camel case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: bool :returns: True/False whether string or iterable is camel case """ return str_or_iter == camelize(str_or_iter) ``` -------------------------------- ### Depascalize String, Dict, or List Source: https://humps.readthedocs.io/en/latest/_modules/humps/main.html Converts a string, dictionary, or list of dictionaries to snake case by calling the decamelize function. Handles nested structures recursively. ```python def depascalize(str_or_iter): """ Convert a string, dict, or list of dicts to snake case. :param str_or_iter: A string or iterable. :type str_or_iter: Union[list, dict, str] :rtype: Union[list, dict, str] :returns: snake cased string, dictionary, or list of dictionaries. """ return decamelize(str_or_iter) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.