dup-fmt


Namedup-fmt JSON
Version 0.1.4 PyPI version JSON
download
home_page
SummaryThe utility formatter objects for the data engine package
upload_time2023-09-07 07:38:10
maintainer
docs_urlNone
author
requires_python>=3.8.10
license
keywords data formatter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Data Utility Package: *Formatter*

[![test](https://github.com/korawica/dup-fmt/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/korawica/dup-fmt/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/korawica/dup-fmt/branch/main/graph/badge.svg?token=J2MN63IFT0)](https://codecov.io/gh/korawica/dup-fmt)
[![python support version](https://img.shields.io/pypi/pyversions/dup-fmt)](https://pypi.org/project/dup-fmt/)
[![size](https://img.shields.io/github/languages/code-size/korawica/dup-fmt)](https://github.com/korawica/dup-fmt)

**Type**: `DUP` | **Tag**: `Data Utility Package` `Data` `Utility` `Formatter`

**Table of Contents**:

- [Formatter Objects](#formatter-objects)
  - [Datetime](#datetime)
  - [Version](#version)
  - [Serial](#serial)
  - [Naming](#naming)
  - [Storage](#storage)
  - [Constant](#constant)
- [FormatterGroup Object](#formattergroup-object)

This **Formatter** package was created for `parse` and `format` any string values
that match format pattern with Python regular expression. This package be the
co-pylot project for stating to my **Python Software Developer** role.

**Install from PyPI**:

```shell
pip install dup-fmt
```

:dart: First objective of this project is include necessary formatter objects for
any data components package which mean we can `parse` any complicate names on
data source and ingest the right names to in-house or data target.

For example, we want to get filename with the format like, `filename_20220101.csv`,
on the file system storage, and we want to incremental ingest the latest file with
date **2022-03-25** date. So we will implement `Datetime` object and parse
that filename to it,

```python
Datetime.parse('filename_20220101.csv', 'filename_%Y%m%d.csv').value == datetime.today()
```

The above example is :yawning_face: **NOT SURPRISE!!!** for us because Python
already provide build-in package `datetime` to parse by `{dt}.strptime` and
format by `{dt}.strftime` with any datetime string value. This package will the
special thing when we group more than one formatter objects together as
`Naming`, `Version`, and `Datetime`.

**For complex filename format like**:

```text
{filename:%s}_{datetime:%Y_%m_%d}.{version:%m.%n.%c}.csv
```

From above filename format string, the `datetime` package does not enough for
this scenario right? but you can handle by your hard-code object or create the
better package than this project.

> **Note**: \
> Any formatter object was implemented the `self.valid` method for help us validate
> format string value like the above example scenario,
> ```python
> this_date = Datetime.parse('20220101', '%Y%m%d')
> this_date.valid('any_files_20220101.csv', 'any_files_%Y%m%d.csv')  # True
> ```

## Formatter Objects

- [Datetime](#datetime)
- [Version](#version)
- [Serial](#serial)
- [Naming](#naming)
- [Storage](#storage)
- [Constant](#constant)

The main purpose is **Formatter Objects** for `parse` and `format` with string
value, such as `Datetime`, `Version`, and `Serial` formatter objects. These objects
were used for parse any filename with put the format string value. The formatter
able to enhancement any format value from sting value, like in `Datetime`, for `%B`
value that was designed for month shortname (`Jan`, `Feb`, etc.) that does not
support in build-in `datetime` package.

> **Note**: \
> The main usage of this formatter object is `parse` and `format` method.

### Datetime

```python
from dup_fmt import Datetime

datetime = Datetime.parse(
   value='This_is_time_20220101_000101',
   fmt='This_is_time_%Y%m%d_%H%M%S'
)
datetime.format('This_datetime_format_%Y%b-%-d_%H:%M:%S')
```

```text
>>> 'This_datetime_format_2022Jan-1_00:01:01'
```

[Supported Datetime formats](/docs/en/docs/API.md#datetime)

### Version

```python
from dup_fmt import Version

version = Version.parse(
    value='This_is_version_2_0_1',
    fmt='This_is_version_%m_%n_%c',
)
version.format('New_version_%m%n%c')
```

```text
>>> 'New_version_201'
```

[Supported Version formats](/docs/en/docs/API.md#version)

### Serial

```python
from dup_fmt import Serial

serial = Serial.parse(
    value='This_is_serial_62130',
    fmt='This_is_serial_%n'
)
serial.format('Convert to binary: %b')
```

```text
>>> 'Convert to binary: 1111001010110010'
```

[Supported Serial formats](/docs/en/docs/API.md#serial)

### Naming

```python
from dup_fmt import Naming

naming = Naming.parse(
    value='de is data engineer',
    fmt='%a is %n'
)
naming.format('Camel case is %c')
```

```text
>>> 'Camel case is dataEngineer'
```

[Supported Naming formats](/docs/en/docs/API.md#naming)

### Storage

```python
from dup_fmt import Storage

storage = Storage.parse(
    value='This file have 250MB size',
    fmt='This file have %M size'
)
storage.format('The byte size is: %b')
```

```text
>>> 'The byte size is: 2097152000'
```

[Supported Storage formats](/docs/en/docs/API.md#storage)

### Constant

```python
from dup_fmt import Constant, make_const
from dup_fmt.exceptions import FormatterError

const = make_const({
    '%n': 'normal',
    '%s': 'special',
})
try:
    parse_const: Constant = const.parse(
        value='This_is_constant_normal',
        fmt='This_is_constant_%n'
    )
    parse_const.format('The value of %%s is %s')
except FormatterError as err:
    print(err)
```

```text
>>> 'The value of %s is special'
```

> **Note**: \
> This package already implement environment constant object, `dup_fmt.EnvConstant`.

## FormatterGroup Object

The **FormatterGroup** object, `FormatterGroup`, which is the grouping of needed
mapping formatter objects and its alias formatter object ref name together. You
can define a name of formatter that you want, such as `name` for `Naming`, or
`timestamp` for `Datetime`.

**Parse**:

```python
from dup_fmt import make_group, Naming, Datetime, FormatterGroupType

group: FormatterGroupType = make_group({'name': Naming, 'datetime': Datetime})
group.parse(
    'data_engineer_in_20220101_de',
    fmt='{name:%s}_in_{timestamp:%Y%m%d}_{name:%a}'
)
```

```text
>>> {
>>>     'name': Naming.parse('data engineer', '%n'),
>>>     'timestamp': Datetime.parse('2022-01-01 00:00:00.000000', '%Y-%m-%d %H:%M:%S.%f')
>>> }
```

**Format**:

```python
from dup_fmt import FormatterGroup
from datetime import datetime

group_01: FormatterGroup = group({
    'name': 'data engineer',
    'datetime': datetime(2022, 1, 1)
})
group_01.format('{name:%c}_{timestamp:%Y_%m_%d}')
```

```text
>>> dataEngineer_2022_01_01
```

## License

This project was licensed under the terms of the [MIT license](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "dup-fmt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.10",
    "maintainer_email": "",
    "keywords": "data,formatter",
    "author": "",
    "author_email": "korawica <korawich.anu@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/38/7c/355a2548030dac315e090afdfb7dd2efa7d8ff4b6c5e7cde266bac2e48a9/dup_fmt-0.1.4.tar.gz",
    "platform": null,
    "description": "# Data Utility Package: *Formatter*\n\n[![test](https://github.com/korawica/dup-fmt/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/korawica/dup-fmt/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/korawica/dup-fmt/branch/main/graph/badge.svg?token=J2MN63IFT0)](https://codecov.io/gh/korawica/dup-fmt)\n[![python support version](https://img.shields.io/pypi/pyversions/dup-fmt)](https://pypi.org/project/dup-fmt/)\n[![size](https://img.shields.io/github/languages/code-size/korawica/dup-fmt)](https://github.com/korawica/dup-fmt)\n\n**Type**: `DUP` | **Tag**: `Data Utility Package` `Data` `Utility` `Formatter`\n\n**Table of Contents**:\n\n- [Formatter Objects](#formatter-objects)\n  - [Datetime](#datetime)\n  - [Version](#version)\n  - [Serial](#serial)\n  - [Naming](#naming)\n  - [Storage](#storage)\n  - [Constant](#constant)\n- [FormatterGroup Object](#formattergroup-object)\n\nThis **Formatter** package was created for `parse` and `format` any string values\nthat match format pattern with Python regular expression. This package be the\nco-pylot project for stating to my **Python Software Developer** role.\n\n**Install from PyPI**:\n\n```shell\npip install dup-fmt\n```\n\n:dart: First objective of this project is include necessary formatter objects for\nany data components package which mean we can `parse` any complicate names on\ndata source and ingest the right names to in-house or data target.\n\nFor example, we want to get filename with the format like, `filename_20220101.csv`,\non the file system storage, and we want to incremental ingest the latest file with\ndate **2022-03-25** date. So we will implement `Datetime` object and parse\nthat filename to it,\n\n```python\nDatetime.parse('filename_20220101.csv', 'filename_%Y%m%d.csv').value == datetime.today()\n```\n\nThe above example is :yawning_face: **NOT SURPRISE!!!** for us because Python\nalready provide build-in package `datetime` to parse by `{dt}.strptime` and\nformat by `{dt}.strftime` with any datetime string value. This package will the\nspecial thing when we group more than one formatter objects together as\n`Naming`, `Version`, and `Datetime`.\n\n**For complex filename format like**:\n\n```text\n{filename:%s}_{datetime:%Y_%m_%d}.{version:%m.%n.%c}.csv\n```\n\nFrom above filename format string, the `datetime` package does not enough for\nthis scenario right? but you can handle by your hard-code object or create the\nbetter package than this project.\n\n> **Note**: \\\n> Any formatter object was implemented the `self.valid` method for help us validate\n> format string value like the above example scenario,\n> ```python\n> this_date = Datetime.parse('20220101', '%Y%m%d')\n> this_date.valid('any_files_20220101.csv', 'any_files_%Y%m%d.csv')  # True\n> ```\n\n## Formatter Objects\n\n- [Datetime](#datetime)\n- [Version](#version)\n- [Serial](#serial)\n- [Naming](#naming)\n- [Storage](#storage)\n- [Constant](#constant)\n\nThe main purpose is **Formatter Objects** for `parse` and `format` with string\nvalue, such as `Datetime`, `Version`, and `Serial` formatter objects. These objects\nwere used for parse any filename with put the format string value. The formatter\nable to enhancement any format value from sting value, like in `Datetime`, for `%B`\nvalue that was designed for month shortname (`Jan`, `Feb`, etc.) that does not\nsupport in build-in `datetime` package.\n\n> **Note**: \\\n> The main usage of this formatter object is `parse` and `format` method.\n\n### Datetime\n\n```python\nfrom dup_fmt import Datetime\n\ndatetime = Datetime.parse(\n   value='This_is_time_20220101_000101',\n   fmt='This_is_time_%Y%m%d_%H%M%S'\n)\ndatetime.format('This_datetime_format_%Y%b-%-d_%H:%M:%S')\n```\n\n```text\n>>> 'This_datetime_format_2022Jan-1_00:01:01'\n```\n\n[Supported Datetime formats](/docs/en/docs/API.md#datetime)\n\n### Version\n\n```python\nfrom dup_fmt import Version\n\nversion = Version.parse(\n    value='This_is_version_2_0_1',\n    fmt='This_is_version_%m_%n_%c',\n)\nversion.format('New_version_%m%n%c')\n```\n\n```text\n>>> 'New_version_201'\n```\n\n[Supported Version formats](/docs/en/docs/API.md#version)\n\n### Serial\n\n```python\nfrom dup_fmt import Serial\n\nserial = Serial.parse(\n    value='This_is_serial_62130',\n    fmt='This_is_serial_%n'\n)\nserial.format('Convert to binary: %b')\n```\n\n```text\n>>> 'Convert to binary: 1111001010110010'\n```\n\n[Supported Serial formats](/docs/en/docs/API.md#serial)\n\n### Naming\n\n```python\nfrom dup_fmt import Naming\n\nnaming = Naming.parse(\n    value='de is data engineer',\n    fmt='%a is %n'\n)\nnaming.format('Camel case is %c')\n```\n\n```text\n>>> 'Camel case is dataEngineer'\n```\n\n[Supported Naming formats](/docs/en/docs/API.md#naming)\n\n### Storage\n\n```python\nfrom dup_fmt import Storage\n\nstorage = Storage.parse(\n    value='This file have 250MB size',\n    fmt='This file have %M size'\n)\nstorage.format('The byte size is: %b')\n```\n\n```text\n>>> 'The byte size is: 2097152000'\n```\n\n[Supported Storage formats](/docs/en/docs/API.md#storage)\n\n### Constant\n\n```python\nfrom dup_fmt import Constant, make_const\nfrom dup_fmt.exceptions import FormatterError\n\nconst = make_const({\n    '%n': 'normal',\n    '%s': 'special',\n})\ntry:\n    parse_const: Constant = const.parse(\n        value='This_is_constant_normal',\n        fmt='This_is_constant_%n'\n    )\n    parse_const.format('The value of %%s is %s')\nexcept FormatterError as err:\n    print(err)\n```\n\n```text\n>>> 'The value of %s is special'\n```\n\n> **Note**: \\\n> This package already implement environment constant object, `dup_fmt.EnvConstant`.\n\n## FormatterGroup Object\n\nThe **FormatterGroup** object, `FormatterGroup`, which is the grouping of needed\nmapping formatter objects and its alias formatter object ref name together. You\ncan define a name of formatter that you want, such as `name` for `Naming`, or\n`timestamp` for `Datetime`.\n\n**Parse**:\n\n```python\nfrom dup_fmt import make_group, Naming, Datetime, FormatterGroupType\n\ngroup: FormatterGroupType = make_group({'name': Naming, 'datetime': Datetime})\ngroup.parse(\n    'data_engineer_in_20220101_de',\n    fmt='{name:%s}_in_{timestamp:%Y%m%d}_{name:%a}'\n)\n```\n\n```text\n>>> {\n>>>     'name': Naming.parse('data engineer', '%n'),\n>>>     'timestamp': Datetime.parse('2022-01-01 00:00:00.000000', '%Y-%m-%d %H:%M:%S.%f')\n>>> }\n```\n\n**Format**:\n\n```python\nfrom dup_fmt import FormatterGroup\nfrom datetime import datetime\n\ngroup_01: FormatterGroup = group({\n    'name': 'data engineer',\n    'datetime': datetime(2022, 1, 1)\n})\ngroup_01.format('{name:%c}_{timestamp:%Y_%m_%d}')\n```\n\n```text\n>>> dataEngineer_2022_01_01\n```\n\n## License\n\nThis project was licensed under the terms of the [MIT license](LICENSE).\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "The utility formatter objects for the data engine package",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/korawica/dup-fmt/",
        "Source Code": "https://github.com/korawica/dup-fmt/"
    },
    "split_keywords": [
        "data",
        "formatter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "efec1f589f5c23636226854db76a1620dcaad8ccf841b14334c4895f89d8e96d",
                "md5": "3fc04cfebed93938c03fce204ebd4054",
                "sha256": "76b68abcfb4c24b8b31b4c21b716e3cc95c6eb1caeba54d719d36b5f5793df6e"
            },
            "downloads": -1,
            "filename": "dup_fmt-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3fc04cfebed93938c03fce204ebd4054",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.10",
            "size": 24699,
            "upload_time": "2023-09-07T07:38:09",
            "upload_time_iso_8601": "2023-09-07T07:38:09.204809Z",
            "url": "https://files.pythonhosted.org/packages/ef/ec/1f589f5c23636226854db76a1620dcaad8ccf841b14334c4895f89d8e96d/dup_fmt-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "387c355a2548030dac315e090afdfb7dd2efa7d8ff4b6c5e7cde266bac2e48a9",
                "md5": "5d635d117d0d4523a522fa9d5c37eeb1",
                "sha256": "c2658d69331e628318af620d03cb0a1d4b01903a12c811954b4b0bf22e4c5edc"
            },
            "downloads": -1,
            "filename": "dup_fmt-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "5d635d117d0d4523a522fa9d5c37eeb1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.10",
            "size": 35758,
            "upload_time": "2023-09-07T07:38:10",
            "upload_time_iso_8601": "2023-09-07T07:38:10.864261Z",
            "url": "https://files.pythonhosted.org/packages/38/7c/355a2548030dac315e090afdfb7dd2efa7d8ff4b6c5e7cde266bac2e48a9/dup_fmt-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-07 07:38:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "korawica",
    "github_project": "dup-fmt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dup-fmt"
}
        
Elapsed time: 0.18953s