A utility library
Project description
A multipurpose utility library for Python 2 and 3.
The library namespace is tocoli. For information on available packages, modules and functionality see Structure.
Highlights
Sorting dictionaries
Sort a ‘list’ of ‘dict’ by simply defining the keys you 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 calls
The dsl package provides a coherent style to access the tocolib modules 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 mapping
Use 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 New
Changed minimum requirement: passlib>=1.7.0
The former dsl module is now an own subpackage.
The keys parameter notation for sorting functions changed.
There are new flags paramter options for mapping functions.
For more detailed information on current changes check the CHANGELOG.md
Structure
Namespace
- tocoli - root
The tocolib wraps the six library (Python 2 and 3 compatibility utilities) at the root. Thus all six packages and modules are also available under the root namespace.
Subpackages
- dsl - a domain specific language for tocolib
Python, 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.
Modules
- auth - common authetication helpers
Its dangerous out there. This module is all about passwords, hashes, salts, tokens and api keys.
- cmp - compare utilities
For those who like to compare apples with pears. Make different data types comparable.
- enc - encoding functions
Encoding without pain. Provides universal encoding functions.
- filter - filter functions
The 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 functions
To Be or not to Be: That is the question! Short value extractor functions and more.
- join - join/reduce/folding functions
Bring together what belongs together.
- map - mapping functions
It’s still magic even if you know how it’s done. Map data by applying any higher-order function to it.
- ratio - ratio functions
Comparisons make unhappy, but can be quite useful. Provides ratio functions for varios purposes.
- regex - regular expression utilities
Find what you are searching for. Generate common regular expressions.
- sort - sort functions
Chuck Norris is able to sort black pens by color. Sort data by value or keys.
- spell - spelling utilities
Life doesn’t come with spell-check, but tocolib does.
- test - testing and benchmarking
Tests cant prove the absence of bugs. Thus test as good as you can.
- type - type conversion utilities
What doesn’t fit is made to fit. Universal type transformations.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tocolib-0.3.1.tar.gz
.
File metadata
- Download URL: tocolib-0.3.1.tar.gz
- Upload date:
- Size: 30.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34eb29a6bfcd8e0f8f5eb5580cba7af44b5a809215fa24999aba08ee6606a3e4 |
|
MD5 | 7badb655dd7dc9fac683a7ba8221617a |
|
BLAKE2b-256 | 6d6cef1166d0125d9d4f09dd0690bca6963f8e4214e7a30d95352233004c1e42 |
File details
Details for the file tocolib-0.3.1-py2.py3-none-any.whl
.
File metadata
- Download URL: tocolib-0.3.1-py2.py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c64f65bc288beb189e77d70da0fac45f40a952f331e78a4fae95d612618a5f5 |
|
MD5 | e2f6be4617a3b0376e55a89138e96eca |
|
BLAKE2b-256 | 966fedd9d19b53b878765689c80f95c0846698a39a02d03c560675f0796c499c |