Skip to main content

pocketutils

Version status License Python version compatibility Version on Docker Hub Version on Github Version on PyPi
Build (Actions) Documentation status Coverage (coveralls) Maintainability (Code Climate) Scrutinizer Code Quality

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) or Chars.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

Metadata

Release files for pocketutils 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pocketutils 0.9.1
File Size Uploaded Provenance
pocketutils-0.9.1.tar.gz 93.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pocketutils 0.9.1
File Interpreter ABI Platform
pocketutils-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 201.5 kB

Release files / pocketutils-0.9.1.tar.gz

Download URL pocketutils-0.9.1.tar.gz
Size 93.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e29f4dfead9866041908a819dc1536f2beaedea461b61ca1bcc95bfc9115b952
BLAKE2b-256 checksum
How to use checksums
357fcafb2264ffc758149aa92de612ef87ef0cb2e05e967563d311567b731e2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Linux/5.15.0-1014-azure

Release files / pocketutils-0.9.1-py3-none-any.whl

Download URL pocketutils-0.9.1-py3-none-any.whl
Size 108.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03a84e85a7f0daca38af2ab6e7f4f47e3456f30273962fcf1a29103dba68620c
BLAKE2b-256 checksum
How to use checksums
9095ba2ba51e32395234ce72a8a34906c4b2b1353300f3d3ac2725e6b08eea47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.9.13 Linux/5.15.0-1014-azure

Security for pocketutils 0.9.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page