Skip to main content

A Tabular Helper utility library with general-purpose helpers for the tha-* ecosystem.

Project description

tha-utils-helper

CI

A small Python utility library with general-purpose helpers for the tha-* ecosystem. No dependencies — just classes with static methods.

Install

pip install tha-utils-helper

Quick start

from tha_utils_helper import ListUtils, DictUtils, TypeUtils

ListUtils.chunk([1, 2, 3, 4, 5], 2)
# [[1, 2], [3, 4], [5]]

DictUtils.safe_get({"student": {"id": 42}}, "student", "id")
# 42

TypeUtils.normalize_bool("yes")
# True

API

ListUtils

Method Description
chunk(lst, size) Split a list into consecutive chunks of size. Final chunk may be smaller. Raises ValueError if size < 1
flatten(lst) Flatten one level of nesting — a list of lists into a single list
ListUtils.chunk([1, 2, 3, 4, 5], 2)   # [[1, 2], [3, 4], [5]]
ListUtils.flatten([[1, 2], [3, 4]])    # [1, 2, 3, 4]

DictUtils

Method Description
pick(d, keys) Return a new dict with only the specified keys
omit(d, keys) Return a new dict with the specified keys removed
safe_get(d, *keys) Traverse nested dicts without raising — returns None if any key is missing or the path hits a non-dict
rename_keys(d, mapping) Return a new dict with keys renamed according to mapping. Unmapped keys are preserved
DictUtils.pick({"a": 1, "b": 2, "c": 3}, ["a", "c"])
# {"a": 1, "c": 3}

DictUtils.omit({"a": 1, "b": 2, "c": 3}, ["b"])
# {"a": 1, "c": 3}

DictUtils.safe_get({"student": {"id": 42}}, "student", "id")
# 42

DictUtils.safe_get({"student": {"id": 42}}, "student", "missing")
# None

DictUtils.rename_keys({"studentUniqueId": 1, "name": "A"}, {"studentUniqueId": "student_id"})
# {"student_id": 1, "name": "A"}

TypeUtils

Method Description
normalize_bool(val) Coerce strings, ints, and bools to bool. Raises ValueError for unrecognized values
safe_int(val) Parse to int, returns None on failure
safe_float(val) Parse to float, returns None on failure

normalize_bool recognizes:

Truthy Falsy
True, 1, "true", "yes", "1", "t", "y" False, 0, "false", "no", "0", "f", "n"

String matching is case-insensitive and strips whitespace.

TypeUtils.normalize_bool("Yes")   # True
TypeUtils.normalize_bool("0")     # False
TypeUtils.normalize_bool("maybe") # raises ValueError

TypeUtils.safe_int("42")   # 42
TypeUtils.safe_int("abc")  # None

TypeUtils.safe_float("3.14")  # 3.14
TypeUtils.safe_float(None)    # None

License

MIT

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

tha_utils_helper-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

tha_utils_helper-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file tha_utils_helper-0.1.1.tar.gz.

File metadata

  • Download URL: tha_utils_helper-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tha_utils_helper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c63bc9949097fa901328f59182aa1ccdfa9db6bdba0881fbc4c11e7a7f010f45
MD5 e8bb738c29900876b73c3531771736cc
BLAKE2b-256 1f20f6caea7662f38d8d7ed009e463e50de9078115a7d5412743b34e50ea2e26

See more details on using hashes here.

Provenance

The following attestation bundles were made for tha_utils_helper-0.1.1.tar.gz:

Publisher: publish.yml on tha-guy-nate/tha-utils-helper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tha_utils_helper-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tha_utils_helper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88b0b202f4b7f2d216fe401ec5dff1c45f669004c1e63e6c3319628839496c6b
MD5 a7cf508601c905aa37993f3fee2e092d
BLAKE2b-256 10af5398c8d950d4de735d752a5aade75bfd35f983302b9f10f9b5f08771779e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tha_utils_helper-0.1.1-py3-none-any.whl:

Publisher: publish.yml on tha-guy-nate/tha-utils-helper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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