ddeutil


Nameddeutil JSON
Version 0.4.4 PyPI version JSON
download
home_pageNone
SummaryCore data utility functions and objects
upload_time2024-12-18 03:08:57
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9.13
licenseMIT
keywords data utility
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Core Data Utility

[![test](https://github.com/korawica/ddeutil/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/korawica/ddeutil/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/ddeutils/ddeutil/graph/badge.svg?token=G3XGBSRKA6)](https://codecov.io/gh/ddeutils/ddeutil)
[![pypi version](https://img.shields.io/pypi/v/ddeutil)](https://pypi.org/project/ddeutil/)
[![python support version](https://img.shields.io/pypi/pyversions/ddeutil)](https://pypi.org/project/ddeutil/)
[![size](https://img.shields.io/github/languages/code-size/korawica/ddeutil)](https://github.com/korawica/ddeutil)
[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![type check: mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

The **Core Data utility** package implements the data utility functions and objects
that was created on sub-package namespace, `ddeutil`, design for independent
installation.

I make 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
> package.

## :round_pushpin: Installation

```shell
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     | Module                                                  |
> |-------------------|---------------------------------------------------------|
> | `ujson`           | `hash.checksum`                                         |
> | `python-dateutil` | `dtutils.next_date_with_freq`, `dtutils.calc_data_freq` | 
> | `psutil`          | `threader.MonitorThread`.                               |

## :dart: Features

This core data package will implement all of utility functions and objects that
does not re-create again because it is basic code 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.                                                                                               |              |
|                 |         `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  |
| 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 arguments 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 `float`.                                                                                                                                                         |              |
|                 |       `str2list`        | Convert an input string value to `list`.                                                                                                                                                          |              |
| base.hash       |       `checksum`        |                                                                                                                                                                                                   |              |
|                 |        `freeze`         |                                                                                                                                                                                                   |              |
|                 |      `freeze_args`      |                                                                                                                                                                                                   |              |
|                 |       `hash_all`        |                                                                                                                                                                                                   |              |
|                 |       `hash_str`        |                                                                                                                                                                                                   |              |
| base.merge      |      `merge_dict`       |                                                                                                                                                                                                   |              |
|                 |   `merge_dict_value`    |                                                                                                                                                                                                   |              |
|                 | `merge_dict_value_list` |                                                                                                                                                                                                   |              |
|                 |      `merge_list`       |                                                                                                                                                                                                   |              |
|                 |      `sum_values`       | Sum all values in an input dict value with start and end index.                                                                                                                                   |              |
|                 |       `zip_equal`       |                                                                                                                                                                                                   |              |
| base.sorting    |        `ordered`        |                                                                                                                                                                                                   |              |
|                 |     `sort_priority`     |                                                                                                                                                                                                   |              |
| base.splitter   |        `isplit`         |                                                                                                                                                                                                   |              |
|                 |      `must_rsplit`      |                                                                                                                                                                                                   |              |
|                 |      `must_split`       |                                                                                                                                                                                                   |              |
| decorator       |       `deepcopy`        |                                                                                                                                                                                                   |              |
|                 |     `deepcopy_args`     |                                                                                                                                                                                                   |              |
|                 |        `timing`         |                                                                                                                                                                                                   |              |
|                 |      `timing_open`      |                                                                                                                                                                                                   |              |
|                 |         `retry`         |                                                                                                                                                                                                   |              |
|                 |        `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`     |                                                                                                                                                                                                   |              |
|                 |    `calc_data_freq`     |                                                                                                                                                                                                   |              |
| 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.                                                                                                                            |              |

## :beers: Usages

I will show some usage example 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 do not complex and you can see how that function work).

### OnlyOne

```python
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

```python
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

```python
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"
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ddeutil",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9.13",
    "maintainer_email": null,
    "keywords": "data, utility",
    "author": null,
    "author_email": "korawica <korawich.anu@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/58/2c/466edde092ebc3abacfc709cf04ec1e35cf82264e6b5d51cbf6efb4d3d2c/ddeutil-0.4.4.tar.gz",
    "platform": null,
    "description": "# Core Data Utility\n\n[![test](https://github.com/korawica/ddeutil/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/korawica/ddeutil/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/ddeutils/ddeutil/graph/badge.svg?token=G3XGBSRKA6)](https://codecov.io/gh/ddeutils/ddeutil)\n[![pypi version](https://img.shields.io/pypi/v/ddeutil)](https://pypi.org/project/ddeutil/)\n[![python support version](https://img.shields.io/pypi/pyversions/ddeutil)](https://pypi.org/project/ddeutil/)\n[![size](https://img.shields.io/github/languages/code-size/korawica/ddeutil)](https://github.com/korawica/ddeutil)\n[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![type check: mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)\n\nThe **Core Data utility** package implements the data utility functions and objects\nthat was created on sub-package namespace, `ddeutil`, design for independent\ninstallation.\n\nI make this package able to extend with any sub-extension with this namespace.\nSo, this namespace able to scale-out the requirement with folder level design.\nYou can add any custom features and import it by `import ddeutil.{extension}`.\n\n> [!NOTE]\n> This package provide the base utility functions and objects for any sub-namespace\n> package.\n\n## :round_pushpin: Installation\n\n```shell\npip install -U ddeutil\n```\n\n**Python version supported**:\n\n| Python Version | Installation                        | Support Fixed Bug  |\n|----------------|-------------------------------------|--------------------|\n| `>=3.9,<3.14`  | `pip install -U ddeutil`            | :heavy_check_mark: |\n\n> [!NOTE]\n> If you want to install all optional dependencies for this package, you can use\n> `pip install -U ddeutil[all]`. For optional dependencies that use on this\n> package, it will list on below table;\n> \n> | Optional deps     | Module                                                  |\n> |-------------------|---------------------------------------------------------|\n> | `ujson`           | `hash.checksum`                                         |\n> | `python-dateutil` | `dtutils.next_date_with_freq`, `dtutils.calc_data_freq` | \n> | `psutil`          | `threader.MonitorThread`.                               |\n\n## :dart: Features\n\nThis core data package will implement all of utility functions and objects that\ndoes not re-create again because it is basic code but has a lot of using require.\n\n| Module          |          Name           | Description                                                                                                                                                                                       | Remark       |\n|:----------------|:-----------------------:|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|\n| base            |   `isinstance_check`    | Return True if a data is instance of the respect instance.                                                                                                                                        |              |\n|                 |     `import_string`     | Import a dotted module path and return the attribute/class designated by the last name in the path.                                                                                               |              |\n|                 |         `lazy`          | Lazy use import_string function that wrapped with partial function.                                                                                                                               |              |\n|                 |       `round_up`        | Round up the number with decimals precision size.                                                                                                                                                 |              |\n|                 |      `remove_pad`       | Remove zero padding of zero prefix string.                                                                                                                                                        |              |\n|                 |         `first`         | Returns the first item in the `iterable` that satisfies the `condition`.                                                                                                                          |              |\n|                 |        `onlyone`        | Get only one element from check list that exists in match list.                                                                                                                                   |              |\n|                 |        `hasdot`         | Return True value if dot searching exists in content data.                                                                                                                                        |              |\n|                 |        `getdot`         | Return the value if dot searching exists in content data.                                                                                                                                         |              |\n|                 |        `setdot`         | Set the value if dot searching exists in content data.                                                                                                                                            |              |\n|                 |      `filter_dict`      | Filter dict value with excluded and included collections.                                                                                                                                         |              |\n|                 |      `random_str`       | Random string from uppercase ASCII and number 0-9.                                                                                                                                                | no coverage  |\n|                 |       `coalesce`        | Coalesce function that is a just naming define function.                                                                                                                                          | no coverage  |\n| 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)                                                                         |              |\n|                 |        `is_int`         | Check an input value that be integer type or not.                                                                                                                                                 |              |\n| base.convert    |       `must_bool`       | Return the boolean value that was converted from string, integer, or boolean value.                                                                                                               |              |\n|                 |       `must_list`       | Return the list value that was converted from string or list value.                                                                                                                               |              |\n|                 |        `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. |              |\n|                 |       `str2args`        | Convert an input arguments string to `args` and `kwargs` values.                                                                                                                                  |              |\n|                 |       `str2bool`        | Convert an input string value to boolean (`True` or `False`).                                                                                                                                     |              |\n|                 |       `str2dict`        | Convert an input string value to `dict`.                                                                                                                                                          |              |\n|                 |     `str2int_float`     | Convert an input string value to `float`.                                                                                                                                                         |              |\n|                 |       `str2list`        | Convert an input string value to `list`.                                                                                                                                                          |              |\n| base.hash       |       `checksum`        |                                                                                                                                                                                                   |              |\n|                 |        `freeze`         |                                                                                                                                                                                                   |              |\n|                 |      `freeze_args`      |                                                                                                                                                                                                   |              |\n|                 |       `hash_all`        |                                                                                                                                                                                                   |              |\n|                 |       `hash_str`        |                                                                                                                                                                                                   |              |\n| base.merge      |      `merge_dict`       |                                                                                                                                                                                                   |              |\n|                 |   `merge_dict_value`    |                                                                                                                                                                                                   |              |\n|                 | `merge_dict_value_list` |                                                                                                                                                                                                   |              |\n|                 |      `merge_list`       |                                                                                                                                                                                                   |              |\n|                 |      `sum_values`       | Sum all values in an input dict value with start and end index.                                                                                                                                   |              |\n|                 |       `zip_equal`       |                                                                                                                                                                                                   |              |\n| base.sorting    |        `ordered`        |                                                                                                                                                                                                   |              |\n|                 |     `sort_priority`     |                                                                                                                                                                                                   |              |\n| base.splitter   |        `isplit`         |                                                                                                                                                                                                   |              |\n|                 |      `must_rsplit`      |                                                                                                                                                                                                   |              |\n|                 |      `must_split`       |                                                                                                                                                                                                   |              |\n| decorator       |       `deepcopy`        |                                                                                                                                                                                                   |              |\n|                 |     `deepcopy_args`     |                                                                                                                                                                                                   |              |\n|                 |        `timing`         |                                                                                                                                                                                                   |              |\n|                 |      `timing_open`      |                                                                                                                                                                                                   |              |\n|                 |         `retry`         |                                                                                                                                                                                                   |              |\n|                 |        `profile`        | Profile the current memory and cpu usage while wrapped function running.                                                                                                                          |              |\n| dtutils         |     `replace_date`      | Replace datetime matrix that less than an input mode to origin value.                                                                                                                             |              |\n|                 |       `next_date`       | Return the next date with specific unit mode.                                                                                                                                                     |              |\n|                 |    `closest_quarter`    | Return closest quarter datetime of an input datetime.                                                                                                                                             |              |\n|                 |       `last_dom`        | Get the latest day of month that relate with an input datetime value.                                                                                                                             |              |\n|                 |       `last_doq`        | Get the latest day of quarter that relate with an input datetime value.                                                                                                                           |              |\n|                 |    `next_date_freq`     |                                                                                                                                                                                                   |              |\n|                 |    `calc_data_freq`     |                                                                                                                                                                                                   |              |\n| threader        |   `ThreadWithControl`   | Threading object that can control maximum background agent and result after complete.                                                                                                             |              |\n|                 |     `MonitorThread`     | Monitoring threading object that log the current memory and cpu usage.                                                                                                                            |              |\n\n## :beers: Usages\n\nI will show some usage example of function in this package. If you want to use\ncomplex or adjust some parameter, please see doc-string or real source code\n(I think it do not complex and you can see how that function work).\n\n### OnlyOne\n\n```python\nfrom ddeutil.core import onlyone\n\nassert 'a' == onlyone(['a', 'b'], ['a', 'b', 'c'])\nassert 'c' == onlyone(('a', 'b'), ['c', 'e', 'f'])\nassert onlyone(['a', 'b'], ['c', 'e', 'f'], default=False) is None\n```\n\n### Instance Check\n\n```python\nfrom ddeutil.core import isinstance_check\nfrom typing import Union, Optional, NoReturn, Any\n\nassert isinstance_check(\"s\", str)\nassert isinstance_check([\"s\"], list[str])\nassert isinstance_check((\"s\", \"t\"), tuple[str, ...])\nassert not isinstance_check((\"s\", \"t\"), tuple[str])\nassert isinstance_check({\"s\": 1, \"d\": \"r\"}, dict[str, Union[int, str]])\nassert isinstance_check(\"s\", Optional[str])\nassert isinstance_check(1, Optional[Union[str, int]])\nassert not isinstance_check(\"s\", list[str])\nassert isinstance_check([1, \"2\"], list[Union[str, int]])\nassert not isinstance_check(\"s\", NoReturn)\nassert isinstance_check(None, NoReturn)\nassert isinstance_check(\"A\", Any)\nassert isinstance_check([1, [1, 2, 3]], list[Union[list[int], int]])\nassert not isinstance_check([1], Union[str, int])\nassert isinstance_check((1, \"foo\", True), tuple[int, str, bool])\n```\n\n### String to Any\n\n```python\nfrom ddeutil.core import str2any\n\nassert str2any(22) == 22\nassert str2any(\"1245\") == 1245\nassert str2any('\"string\"') == \"string\"\nassert str2any(\"[1, 2, 3]\") == [1, 2, 3]\nassert str2any('{\"key\": \"value\"}') == {\"key\": \"value\"}\nassert str2any(\"1245.123\") == 1245.123\nassert str2any(\"True\")\nassert str2any(\"[1, 2\") == \"[1, 2\"\nassert str2any(\"1.232.1\") == \"1.232.1\"\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Core data utility functions and objects",
    "version": "0.4.4",
    "project_urls": {
        "Homepage": "https://github.com/ddeutils/ddeutil/",
        "Source Code": "https://github.com/ddeutils/ddeutil/"
    },
    "split_keywords": [
        "data",
        " utility"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c39212e01a3bfea84a8489737b5e59c5fc1f0f1ad0c5266e11951aa299035c2",
                "md5": "ca7b1fb934e0142c6e2791345a332152",
                "sha256": "ad2ef40e7da1bcfcead27ade560298983f3c226aa1572d8a5b9757124602f778"
            },
            "downloads": -1,
            "filename": "ddeutil-0.4.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ca7b1fb934e0142c6e2791345a332152",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.13",
            "size": 25300,
            "upload_time": "2024-12-18T03:08:56",
            "upload_time_iso_8601": "2024-12-18T03:08:56.046098Z",
            "url": "https://files.pythonhosted.org/packages/9c/39/212e01a3bfea84a8489737b5e59c5fc1f0f1ad0c5266e11951aa299035c2/ddeutil-0.4.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "582c466edde092ebc3abacfc709cf04ec1e35cf82264e6b5d51cbf6efb4d3d2c",
                "md5": "3ffa334df4ff58e2b17737d7c443ea97",
                "sha256": "3e212c7a6c858faa06c73782dc3cb2bb0d71162cb5fe7ed509bbf03a7a18a416"
            },
            "downloads": -1,
            "filename": "ddeutil-0.4.4.tar.gz",
            "has_sig": false,
            "md5_digest": "3ffa334df4ff58e2b17737d7c443ea97",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.13",
            "size": 29703,
            "upload_time": "2024-12-18T03:08:57",
            "upload_time_iso_8601": "2024-12-18T03:08:57.284622Z",
            "url": "https://files.pythonhosted.org/packages/58/2c/466edde092ebc3abacfc709cf04ec1e35cf82264e6b5d51cbf6efb4d3d2c/ddeutil-0.4.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 03:08:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ddeutils",
    "github_project": "ddeutil",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ddeutil"
}
        
Elapsed time: 0.49849s