Random useful stuff
Maintained. Last release 4 days ago, commits in 3 of the last 26 weeks. Weaker on commit activity.
pip install trickkistetrickkiste
trickkiste is a collection of convenience functionality I use quite often that
are too small to give them their own project on the one side but prone to
changes due to changes to the Python ecosystem to just copy&paste them and leave
them as they are.
So they are here now, enjoy.
Beware: most of this is not part of any standard library for a reason. That reason might be there are better built in solutions which are harder (but more flexible) to use or I just didn't find them back then. In most cases you're advised to build them your own (to avoid dependencies and bugs).
Content
Here is an overview of what's in here, see the docstings for a better description (some even have a doctest!):
misc
-
throw(BaseException): functionalraisefor closed expressions -
md5from(Path): convenient wrapper returning an MD5 file checksum -
cwd(Path): path changing context manager -
process_output(cmd): short form for 'run a command and return it's output as one string' -
asyncify: decorator turning a sync method or function into an async one -
async_chain: likechainbut async -
async_filter: likefilterbut async -
date_str(timestamp, [datefmt]): convenience wrapper forstrftime -
def date_from(timestamp: float | str): : convenience wrapper forstrptime -
dur_str(seconds, [fixed]): short human readable representation of a duration -
age_str(now, age, [fixed]): likedur_strbut with an age context -
parse_age(string: str): inverse ofage_str -
smart_split(string: str, delimiter: str = ","): likesplitbut parenthesis aware! -
multi_replace(string: str, *substitutions: tuple[str, str]): short form for chaingingreplace -
compact_dict(mapping, [maxlen], [delim]): create a short one-string map