/00 /00 /00
| 00 |__/| 00
/00 /00 /000000 /00| 00 /0000000
| 00 | 00|_ 00_/ | 00| 00 /00_____/
| 00 | 00 | 00 | 00| 00| 000000
| 00 | 00 | 00 /00| 00| 00 \____ 00
| 000000/ | 0000/| 00| 00 /0000000/
\______/ \___/ |__/|__/|_______/ utils is a collection of Python helper typed functions.
- The functions provided by
utilsare typed in the sense pythonalta/typed. This means that they are type-checked at runtime, providing type safety. - Even as possible,
utilsprovide solutions to minor external libraries. For example, for management ofenvswe have our own functions, which works as a replacement forpythondotenv. - We try to avoid dependencies at most. However, if a dependency is needed, it is automatically installed at runtime if needed.
With pip:
pip install git+https://github.com/pythonalta/utils With py:
py i pythonalta/utils The only global dependency is typed.
utils/
|-- __init__.py ..... importing everthing in main.py
|-- main.py .......... importing the utility classes
|-- err.py ........... with error classes
└-- mods/ ............ with files defining utility classes
To each mod file in mods/ there corresponds a namesake class. The class, in turn, provide the utility functions for the underlying context. To each mod in mods/ there also corresponds an error class, as below, which is an extension of the base class Exception.
mod class meaning error
-----------------------------------------------------
str.py str string utilities StrErr
json_.py json json utilities JsonErr
path.py path path utilities PathErr
file.py file file utilities FileErr
lib.py lib libs utilities LibErr
date.py date date utilities DateErr
color.py color color utilities ColorErr
img.py img image utilities ImgErr
md.py md markdown utilities MDErr
... ... ... ...
A utility is a function in a mod file satisfying the following conditions:
- it is
typedin the sense of typed - all types used in the function type hints are constructed in the
typedlibrary - it has a global
try/exceptblock that raises the correspondingerrorclass of themod.
This means that the general form of a utility is as follows:
from typed import typed, SomeType, OtherType, ReturnType, ...
from utils.err import SomeModErr
class some_mod:
...
@typed
def some_utility(x: SomeType, y: OtherType, ...) -> ReturType:
try:
...
except Exception as e:
raise SomeModErr