Skip to main content

Adorable little Python code for you to copy or import.

Project description

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.

pip install pocketutils or pip install pocketutils[all] Apache-licensed.

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

Project details


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.8.4.tar.gz (93.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pocketutils-0.8.4-py3-none-any.whl (108.6 kB view details)

Uploaded Python 3

File details

Details for the file pocketutils-0.8.4.tar.gz.

File metadata

  • Download URL: pocketutils-0.8.4.tar.gz
  • Upload date:
  • Size: 93.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

File hashes

Hashes for pocketutils-0.8.4.tar.gz
Algorithm Hash digest
SHA256 c6145293a38539a19bfde10445e8ac88d3d121b075e66790fe6b2b405549bbc3
MD5 84a645e24e32286d0d1e7b2b2b07e8c0
BLAKE2b-256 116af5b036ada05e66e13ca0ae8dbbe7b90bed4d0ec051fcb1f6a7529f2a895a

See more details on using hashes here.

File details

Details for the file pocketutils-0.8.4-py3-none-any.whl.

File metadata

  • Download URL: pocketutils-0.8.4-py3-none-any.whl
  • Upload date:
  • Size: 108.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.7 Linux/5.8.0-1042-azure

File hashes

Hashes for pocketutils-0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1b13c5b2ce81c6a066e082d4c21038e7584d6ed92250e78a55510f8c9e5bf7e2
MD5 5a6a3c94e82828c4b0f0ef77fdb31a54
BLAKE2b-256 c6adee29b4403209cc9fb5db99b5fe3ec545b61092294bf962bf0361276d98f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page