Package: tocolib
A multipurpose utility library for Python 2 and 3.The library namespace istocoli. For information on
available packages, modules and functionality seeStructure.HighlightsSorting dictionariesSort a ‘list’ of ‘dict’ by simply defining thekeysyou like to sort
by in order from last to first.Example:>>> dicts = [{'firstname': 'Bob',   'lastname': 'Abel'},
             {'firstname': 'Alice', 'lastname': 'Bond'},
             {'firstname': 'Carol', 'lastname': 'Bond'},
             {'firstname': 'Bob',   'lastname': 'Bond'},
             {'firstname': 'Carol', 'lastname': 'Abel'},
             {'firstname': 'Alice', 'lastname': 'Abel'}]>>> from tocoli.sort import sort_dicts_by_value
>>> sort_dicts_by_value(dicts, ['lastname', 'firstname'])
[{'firstname': 'Alice', 'lastname': 'Abel'},
 {'firstname': 'Bob',   'lastname': 'Abel'},
 {'firstname': 'Carol', 'lastname': 'Abel'},
 {'firstname': 'Alice', 'lastname': 'Bond'},
 {'firstname': 'Bob',   'lastname': 'Bond'},
 {'firstname': 'Carol', 'lastname': 'Bond'}]A Domain Specific Language for intuitive function callsThedslpackage provides a coherent style to access thetocolibmodules and functions as module or static class functions.Example:>>> from tocoli.dsl import sort>>> sort.dicts.by.value(dicts, ['lastname', 'firstname'])
[{'firstname': 'Alice', 'lastname': 'Abel'},
 {'firstname': 'Bob',   'lastname': 'Abel'},
 {'firstname': 'Carol', 'lastname': 'Abel'},
 {'firstname': 'Alice', 'lastname': 'Bond'},
 {'firstname': 'Bob',   'lastname': 'Bond'},
 {'firstname': 'Carol', 'lastname': 'Bond'}]>>> sort.dicts.by.similarity(dicts, 'Karol', ['firstname'])
[{'firstname': 'Carol', 'lastname': 'Bond'},
 {'firstname': 'Carol', 'lastname': 'Abel'},
 {'firstname': 'Alice', 'lastname': 'Bond'},
 {'firstname': 'Alice', 'lastname': 'Abel'},
 {'firstname': 'Bob',   'lastname': 'Abel'},
 {'firstname': 'Bob',   'lastname': 'Bond'}]Powerful mappingUse recursive mapping to apply functions to nested data structures.Example:>>> from tocoli.dsl import map>>> def upper(item, parent):
        return item.upper()>>> map.recursive(dicts, upper)
[{'firstname': 'BOB', 'lastname': 'ABEL'},
 {'firstname': 'ALICE', 'lastname': 'BOND'},
 {'firstname': 'CAROL', 'lastname': 'BOND'},
 {'firstname': 'BOB', 'lastname': 'BOND'},
 {'firstname': 'CAROL', 'lastname': 'ABEL'},
 {'firstname': 'ALICE', 'lastname': 'ABEL'}]>>> map_keys = (map.DEFAULT | map.DICT_KEY) ^ map.DICT_VALUE
>>> map.recursive(dicts, upper, map_keys)
[{'FIRSTNAME': 'Bob', 'LASTNAME': 'Abel'},
 {'FIRSTNAME': 'Alice', 'LASTNAME': 'Bond'},
 {'FIRSTNAME': 'Carol', 'LASTNAME': 'Bond'},
 {'FIRSTNAME': 'Bob', 'LASTNAME': 'Bond'},
 {'FIRSTNAME': 'Carol', 'LASTNAME': 'Abel'},
 {'FIRSTNAME': 'Alice', 'LASTNAME': 'Abel'}]What’s NewChanged minimum requirement: passlib>=1.7.0The formerdslmodule is now an own subpackage.Thekeysparameter notation for sorting functions changed.There are newflagsparamter options for mapping functions.For more detailed information on current changes check theCHANGELOG.mdStructureNamespacetocoli- rootThe tocolib wraps thesixlibrary (Python 2 and 3 compatibility utilities)
at the root. Thus allsixpackages and modules are also available under the
root namespace.Subpackagesdsl- a domain specific language for tocolibPython, like it should be. The module contains a domain specific language
for common functions like filtering, sorting, mapping and more. All
functions have a consistent API and results.Modulesauth- common authetication helpersIts dangerous out there. This module is all about passwords, hashes, salts,
tokens and api keys.cmp- compare utilitiesFor those who like to compare apples with pears. Make different data types
comparable.enc- encoding functionsEncoding without pain. Provides universal encoding functions.filter- filter functionsThe good ones go into the pot, the bad ones go into your crop. Advanced
functions to filter dictionaries or lists of strings.fn- common lambda functionsTo Be or not to Be: That is the question! Short value extractor functions
and more.join- join/reduce/folding functionsBring together what belongs together.map- mapping functionsIt’s still magic even if you know how it’s done. Map data by applying any
higher-order function to it.ratio- ratio functionsComparisons make unhappy, but can be quite useful. Provides ratio
functions for varios purposes.regex- regular expression utilitiesFind what you are searching for. Generate common regular expressions.sort- sort functionsChuck Norris is able to sort black pens by color. Sort data by value or keys.spell- spelling utilitiesLife doesn’t come with spell-check, but tocolib does.test- testing and benchmarkingTests cant prove the absence of bugs. Thus test as good as you can.type- type conversion utilitiesWhat doesn’t fit is made to fit. Universal type transformations.