Welcome to Fmtutil
Lightweight formatter objects, this fmtutil package was created for parse
and format
any string values that match a format pattern which created base on
Python regular expression.
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.
Installation
Python version supported:
Python Version | Installation | Support Fixed Bug |
---|---|---|
== 3.8 |
pip install "fmtutil>=0.4,<0.5.0" |
|
>=3.9,<3.13 |
pip install -U fmtutil |
Note
This package has one dependency package, python-dateutil
, this package use
for support add and sub datetime value on the Datetime formatter only.
If you do not want to install this package, you can use pip install -U fmtutil
.
Introduction
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,
assert (
Datetime.parse('filename_20220101.csv', 'filename_%Y%m%d.csv').value
== datetime.datetime(2022, 1, 1, 0)
)
The above example is NOT SURPRISE!!! for you right?
Because the Python already provide the build-in
datetime
to parse by datetime.strptime
and format by {dt}.strftime
.
This package will be the special thing when we group more than one format-able
objects together as Naming
, Version
, and Datetime
.
For a complex filename format like ;
Warning
Disclaimer: The above filename format, the datetime
package that already
build-in in Python does not enough for this scenario but you can handle by your
code function 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 the example scenario,
Next Step
I will change formatter object construction from changing with inside method to
assert design. The code already implement and testing stage at file __assets.py
.
That mean, you can create any formatter object by dynamic asset changed strategy.
class Datetime(Formatter, asset=DATETIME_ASSET, config=DATETIME_CONF, level=10):
"""Datetime Formatter object."""
...
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
for fix bug or request new feature if you want it.