Adorable little Python code for you to copy or import.
Project description
pocketutils
Adorable little Python functions for you to copy or import, Apache-licensed.
pip install pocketutils
or
pip install pocketutils[all]
Basic usage – Tools
from pocketutils.full import Tools
Tools.zip_strict([1, 2, 3], [5, 6]) # error <-- lengths must match
Tools.strip_brackets("( (xy)") # "(xy" <-- strips paired only
Tools.sanitize_path("x\ty") # "xy" <-- very robust cross-platform sanitization
Tools.delete_surefire("my_file") # <-- Attempts to fix permissions if needed
Tools.git_description("my_repo").tag # <-- get git repo info
Tools.pretty_function(lambda s: None) # "<λ(1)> <-- decent name for any object
Tools.roman_to_arabic("XIV") # 14 <-- inverse function too
Tools.delta_time_to_str(delta_sec=60 * 2 + 5) # "02:05" <-- handles days too
Tools.round_to_sigfigs(135.3, 2) # 140 <-- rounding to sigfigs-proper
Tools.pretty_float(-float("-inf")) # "−∞" <-- proper unicode, no trailing 0s
Tools.stream_cmd_call(["cat", "big-file"], callback=fn) # <-- buffer never fills
Tools.strip_off("hippopotamus", "hippo") # "potamus" <-- what .strip() should do
Tools.strip_quotes("'hello'") # "hello"
Tools.truncate10("looong string") # "looong st…"
Tools.parse_bool("true") # True
Tools.parse_bool_flex("yes") # True
Tools.look(item, "purchase.buyer.first_name") # None if purchase or buyer is None
Tools.friendly_size(n_bytes=2 * 14) # "16.38 kb"
Tools.is_probable_null("NaN") # True
Tools.is_true_iterable("kitten") # False
Tools.or_null(some_function) # None if it fails
Tools.or_raise(None) # raises an error (of your choice)
Tools.trash(unwanted_file) # move to os-specific trash
Tools.pretty_dict({"contents": {"greeting": "hi"}}) # indented
Tools.save_diagnostics(Tools.get_env_info()) # record diagnostic info
Tools.is_lambda(lambda: None) # True
Tools.longest(["a", "a+b"]) # "a+b" # anything with len
Tools.only([1, 2]) # error -- multiple items
Tools.first(iter([])) # None <-- better than try: next(iter(x)) except:...
Tools.trace_signals(sink=sys.stderr) # log traceback on all signals
Tools.trace_exit(sink=sys.stderr) # log traceback on exit
# lots of others
More things
FancyLoguru
(really useful)NestedDotDict
(esp. for toml and json)QueryUtils
(handles rate-limiting, etc.)FigTools
(for matplotlib)J
(tools to interact with Jupyter)WB1
(microwell plate nomenclature)Chars
(e.g.Chars.shelled(s)
orChars.snowflake
)exceptions
(general-purpose exceptions that can store relevant info)
Even more, albeit more obscure:
TissueExpression
,UniprotGo
,AtcTree
,PlateRois
WebResource
,magic_template
color_schemes
,FigSaver
,RefDims
LoopTools
MemCache
See the docs 📚, or just
browse the code.
New issues and pull requests are welcome.
Please refer to the contributing guide
and security policy.
Generated with tyrannosaurus: tyrannosaurus new tyrannosaurus
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
pocketutils-0.9.0.tar.gz
(93.0 kB
view hashes)
Built Distribution
pocketutils-0.9.0-py3-none-any.whl
(108.5 kB
view hashes)
Close
Hashes for pocketutils-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20df751c70bc27bf04028264e02a60cde06672a5cc6fccb6ced3e8c7041fde26 |
|
MD5 | b55b1de1697bc13c32e871cf6ec0aa45 |
|
BLAKE2b-256 | 81ea237111da5d1222add29b897c6b1d780467a282f40703fce25e815369680c |