Skip to main content

Core Utility

test codecov pypi version python support version size code style: black type check: mypy pre-commit

A Core Utility package that implements the data utility functions and objects.

I was created this package base on sub-package namespace, ddeutil (This feature use for independent installation). This package able to extend with any sub-extension with this namespace. So, this namespace able to scale-out the requirement with folder level design. You can add any custom features and import it by import ddeutil.{extension}.

[!NOTE] This package provide the base utility functions and objects for any sub-namespace ddeutil package.

:round_pushpin: Installation

pip install -U ddeutil

Python version supported:

Python Version Installation Support Fixed Bug
>=3.9,<3.14 pip install -U ddeutil :heavy_check_mark:

[!NOTE] If you want to install all optional dependencies for this package, you can use pip install -U ddeutil[all]. For optional dependencies that use on this package, it will list on below table;

Optional deps Installation Modules
ujson ddeutil[checksum] hash.checksum
python-dateutil ddeutil[dateutil] dtutils.next_date_with_freq, dtutils.calc_data_freq
psutil ddeutil[memory] threader.MonitorThread.

:dart: Features

This data package implements all of utility functions and objects that does not re-create again when the sub-namespace package want it because it is a basic utility but has a lot of using require.

Module Name Description Remark
base isinstance_check Return True if a data is instance of the respect instance.
import_string Import a dotted module path and return the attribute/class designated by the last name in the path. no coverage
lazy Lazy use import_string function that wrapped with partial function.
round_up Round up the number with decimals precision size.
remove_pad Remove zero padding of zero prefix string.
first Returns the first item in the iterable that satisfies the condition.
onlyone Get only one element from check list that exists in match list.
hasdot Return True value if dot searching exists in content data.
getdot Return the value if dot searching exists in content data.
setdot Set the value if dot searching exists in content data.
filter_dict Filter dict value with excluded and included collections.
random_str Random string from uppercase ASCII and number 0-9. no coverage
coalesce Coalesce function that is a just naming define function. no coverage
check_and_remove_item Check item before remove it in the target list. no coverage
base.checker can_int Check an input value that can be integer type or not (but some value does not use int() to convert it such as 0.0 or 3.0)
is_int Check an input value that be integer type or not.
base.convert must_bool Return the boolean value that was converted from string, integer, or boolean value.
must_list Return the list value that was converted from string or list value.
str2any Convert an input string value to the real type of that object. Note that this convert function do not force or try-hard to convert type such as a boolean value should be 'True' or 'False' only.
str2args Convert an input string to args and kwargs values.
str2bool Convert an input string value to boolean (True or False).
str2dict Convert an input string value to dict.
str2int_float Convert an input string value to int or float.
str2list Convert an input string value to list.
base.hash checksum
freeze no coverage
freeze_args no coverage
hash_value
hash_str
base.merge merge_dict Given any number of dictionaries, shallow copy and merge into a new dict, precedence goes to key-value pairs in latter dictionaries.
merge_dict_value Merge value of dicts together if it has a same key.
merge_dict_value_list Merge value that be list type of dicts together if it has a same key.
merge_list Merge lists together.
sum_values Sum all values in an input dict value with start and end index.
zip_equal
add_list_value Add value to dict with an input specific key that should be appended or make a new list of this value if key does not exist.
base.sorting ordered
sort_priority
base.splitter isplit
must_rsplit
must_split
decorator deepcopy Deep-copy any args and kwargs for func and method.
retry Retry decorator with sequential.
profile Profile the current memory and cpu usage while wrapped function running.
dtutils replace_date Replace datetime matrix that less than an input mode to origin value.
next_date Return the next date with specific unit mode.
closest_quarter Return closest quarter datetime of an input datetime.
last_dom Get the latest day of month that relate with an input datetime value.
last_doq Get the latest day of quarter that relate with an input datetime value.
next_date_freq Prepare datetime to next datetime with frequency value.
calc_date_freq Prepare datetime to calculate datetime with frequency value.
threader ThreadWithControl Threading object that can control maximum background agent and result after complete.
MonitorThread Monitoring threading object that log the current memory and cpu usage.

:star: Usages

I will show some examples of function in this package. If you want to use complex or adjust some parameter, please see doc-string or real source code (I think it does not complex, and you can see how that function work).

OnlyOne

from ddeutil.core import onlyone

assert 'a' == onlyone(['a', 'b'], ['a', 'b', 'c'])
assert 'c' == onlyone(('a', 'b'), ['c', 'e', 'f'])
assert onlyone(['a', 'b'], ['c', 'e', 'f'], default=False) is None

Instance Check

from ddeutil.core import isinstance_check
from typing import Union, Optional, NoReturn, Any

assert isinstance_check("s", str)
assert isinstance_check(["s"], list[str])
assert isinstance_check(("s", "t"), tuple[str, ...])
assert not isinstance_check(("s", "t"), tuple[str])
assert isinstance_check({"s": 1, "d": "r"}, dict[str, Union[int, str]])
assert isinstance_check("s", Optional[str])
assert isinstance_check(1, Optional[Union[str, int]])
assert not isinstance_check("s", list[str])
assert isinstance_check([1, "2"], list[Union[str, int]])
assert not isinstance_check("s", NoReturn)
assert isinstance_check(None, NoReturn)
assert isinstance_check("A", Any)
assert isinstance_check([1, [1, 2, 3]], list[Union[list[int], int]])
assert not isinstance_check([1], Union[str, int])
assert isinstance_check((1, "foo", True), tuple[int, str, bool])

String to Any

from ddeutil.core import str2any

assert str2any('22') == 22
assert str2any("1245") == 1245
assert str2any('"string"') == "string"
assert str2any("[1, 2, 3]") == [1, 2, 3]
assert str2any('{"key": "value"}') == {"key": "value"}
assert str2any("1245.123") == 1245.123
assert str2any("True")
assert str2any("[1, 2") == "[1, 2"
assert str2any("1.232.1") == "1.232.1"

:speech_balloon: Contribute

I do not think this project will go around the world because it has specific propose, and you can create by your coding without this project dependency for long term solution. So, on this time, you can open the GitHub issue on this project :raised_hands: for fix bug or request new feature if you want it.

Metadata

Release files for ddeutil 0.4.10

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

Source distribution (sdist)

Source distribution for ddeutil 0.4.10
File Size Uploaded
ddeutil-0.4.10.tar.gz 35.7 kB Details

Built distribution (wheel)

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

Total release size: 65.3 kB

Release files / ddeutil-0.4.10.tar.gz

Download URL ddeutil-0.4.10.tar.gz
Size 35.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dadd85da35020e4c6b80a66e8c07a5e998d077b8c7ab5b5a3e3ef3d119691bce
BLAKE2b-256 checksum
How to use checksums
a6c6ad814aa56bcefa43f416c5f8cfd4ae759916c254f196cfdbea10fa7494c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / ddeutil-0.4.10-py3-none-any.whl

Download URL ddeutil-0.4.10-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
174a1e8993aa5d9b5c19107b96eeefb855e875bea511a505e3216465910b5470
BLAKE2b-256 checksum
How to use checksums
50b88141e7f3d2eaa515c6249a6ce2f4c79d082c2197f36f1c359a02edb677a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.4.10 This release

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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