A Tabular Helper utility library with general-purpose helpers for the tha-* ecosystem.
Project description
tha-utils-helper
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c63bc9949097fa901328f59182aa1ccdfa9db6bdba0881fbc4c11e7a7f010f45
|
|
| MD5 |
e8bb738c29900876b73c3531771736cc
|
|
| BLAKE2b-256 |
1f20f6caea7662f38d8d7ed009e463e50de9078115a7d5412743b34e50ea2e26
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tha_utils_helper-0.1.1.tar.gz -
Subject digest:
c63bc9949097fa901328f59182aa1ccdfa9db6bdba0881fbc4c11e7a7f010f45 - Sigstore transparency entry: 1557328322
- Sigstore integration time:
-
Permalink:
tha-guy-nate/tha-utils-helper@3f5b7e521c6de26486af8b59084d46651a14441f -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tha-guy-nate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3f5b7e521c6de26486af8b59084d46651a14441f -
Trigger Event:
push
-
Statement type:
File details
Details for the file tha_utils_helper-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tha_utils_helper-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88b0b202f4b7f2d216fe401ec5dff1c45f669004c1e63e6c3319628839496c6b
|
|
| MD5 |
a7cf508601c905aa37993f3fee2e092d
|
|
| BLAKE2b-256 |
10af5398c8d950d4de735d752a5aade75bfd35f983302b9f10f9b5f08771779e
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tha_utils_helper-0.1.1-py3-none-any.whl -
Subject digest:
88b0b202f4b7f2d216fe401ec5dff1c45f669004c1e63e6c3319628839496c6b - Sigstore transparency entry: 1557328701
- Sigstore integration time:
-
Permalink:
tha-guy-nate/tha-utils-helper@3f5b7e521c6de26486af8b59084d46651a14441f -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tha-guy-nate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3f5b7e521c6de26486af8b59084d46651a14441f -
Trigger Event:
push
-
Statement type: