potato-util 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- potato_util/__init__.py +6 -0
- potato_util/__version__.py +1 -0
- potato_util/_base.py +117 -0
- potato_util/constants/__init__.py +5 -0
- potato_util/constants/_base.py +5 -0
- potato_util/constants/_enum.py +31 -0
- potato_util/constants/_regex.py +23 -0
- potato_util/dt.py +240 -0
- potato_util/http/__init__.py +12 -0
- potato_util/http/_async.py +42 -0
- potato_util/http/_base.py +46 -0
- potato_util/http/_sync.py +45 -0
- potato_util/http/fastapi.py +26 -0
- potato_util/io/__init__.py +11 -0
- potato_util/io/_async.py +274 -0
- potato_util/io/_sync.py +264 -0
- potato_util/sanitizer.py +85 -0
- potato_util/secure.py +90 -0
- potato_util/validator.py +150 -0
- potato_util-0.0.1.dist-info/METADATA +287 -0
- potato_util-0.0.1.dist-info/RECORD +24 -0
- potato_util-0.0.1.dist-info/WHEEL +5 -0
- potato_util-0.0.1.dist-info/licenses/LICENSE.txt +21 -0
- potato_util-0.0.1.dist-info/top_level.txt +1 -0
potato_util/secure.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
import string
|
|
3
|
+
import secrets
|
|
4
|
+
import hashlib
|
|
5
|
+
|
|
6
|
+
from pydantic import validate_call
|
|
7
|
+
|
|
8
|
+
from .constants import HashAlgoEnum
|
|
9
|
+
from .dt import now_ts
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@validate_call
|
|
13
|
+
def gen_unique_id(prefix: str = "") -> str:
|
|
14
|
+
"""Generate unique id. Format: '{prefix}{datetime}_{uuid4}'.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
prefix (str, optional): Prefix of id. Defaults to ''.
|
|
18
|
+
|
|
19
|
+
Raises:
|
|
20
|
+
ValueError: If `prefix` length is greater than 32.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
str: Unique id.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
prefix = prefix.strip()
|
|
27
|
+
if 32 < len(prefix):
|
|
28
|
+
raise ValueError(
|
|
29
|
+
f"`prefix` argument length {len(prefix)} is too long, must be less than or equal to 32!",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
_id = str(f"{prefix}{now_ts()}_{uuid.uuid4().hex}").lower()
|
|
33
|
+
return _id
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@validate_call
|
|
37
|
+
def gen_random_string(length: int = 16, is_alphanum: bool = True) -> str:
|
|
38
|
+
"""Generate secure random string.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
length (int , optional): Length of random string. Defaults to 16.
|
|
42
|
+
is_alphanum (bool, optional): If True, generate only alphanumeric string. Defaults to True.
|
|
43
|
+
|
|
44
|
+
Raises:
|
|
45
|
+
ValueError: If `length` is less than 1.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
str: Generated random string.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
if length < 1:
|
|
52
|
+
raise ValueError(
|
|
53
|
+
f"`length` argument value {length} is too small, must be greater than or equal to 1!",
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
_base_chars = string.ascii_letters + string.digits
|
|
57
|
+
if not is_alphanum:
|
|
58
|
+
_base_chars += string.punctuation
|
|
59
|
+
|
|
60
|
+
_random_str = "".join(secrets.choice(_base_chars) for _i in range(length))
|
|
61
|
+
return _random_str
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@validate_call
|
|
65
|
+
def hash_str(val: str | bytes, algorithm: HashAlgoEnum = HashAlgoEnum.sha256) -> str:
|
|
66
|
+
"""Hash a string using a specified hash algorithm.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
val (str | bytes , required): The value to be hashed.
|
|
70
|
+
algorithm (HashAlgoEnum, required): The hash algorithm to use. Defaults to `HashAlgoEnum.sha256`.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
str: The hexadecimal representation of the digest.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
if isinstance(val, str):
|
|
77
|
+
val = val.encode("utf-8")
|
|
78
|
+
|
|
79
|
+
_hash = hashlib.new(algorithm.value)
|
|
80
|
+
_hash.update(val)
|
|
81
|
+
|
|
82
|
+
_hash_val = _hash.hexdigest()
|
|
83
|
+
return _hash_val
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
__all__ = [
|
|
87
|
+
"gen_unique_id",
|
|
88
|
+
"gen_random_string",
|
|
89
|
+
"hash_str",
|
|
90
|
+
]
|
potato_util/validator.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from re import Pattern
|
|
3
|
+
|
|
4
|
+
from pydantic import validate_call
|
|
5
|
+
|
|
6
|
+
from .constants import (
|
|
7
|
+
REQUEST_ID_REGEX,
|
|
8
|
+
SPECIAL_CHARS_BASE_REGEX,
|
|
9
|
+
SPECIAL_CHARS_LOW_REGEX,
|
|
10
|
+
SPECIAL_CHARS_MEDIUM_REGEX,
|
|
11
|
+
SPECIAL_CHARS_HIGH_REGEX,
|
|
12
|
+
SPECIAL_CHARS_STRICT_REGEX,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@validate_call
|
|
17
|
+
def is_truthy(val: str | bool | int | float | None) -> bool:
|
|
18
|
+
"""Check if the value is truthy.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
val (Union[str, bool, int, float, None], required): Value to check.
|
|
22
|
+
|
|
23
|
+
Raises:
|
|
24
|
+
ValueError: If `val` argument type is string and value is invalid.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
bool: True if the value is truthy, False otherwise.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
if isinstance(val, str):
|
|
31
|
+
val = val.strip().lower()
|
|
32
|
+
|
|
33
|
+
if val in ["0", "false", "f", "no", "n", "off"]:
|
|
34
|
+
return False
|
|
35
|
+
elif val in ["1", "true", "t", "yes", "y", "on"]:
|
|
36
|
+
return True
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError(f"`val` argument value is invalid: '{val}'!")
|
|
39
|
+
|
|
40
|
+
return bool(val)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@validate_call
|
|
44
|
+
def is_falsy(val: str | bool | int | float | None) -> bool:
|
|
45
|
+
"""Check if the value is falsy.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
val (Union[str, bool, int, float, None], required): Value to check.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
bool: True if the value is falsy, False otherwise.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
return not is_truthy(val)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@validate_call
|
|
58
|
+
def is_request_id(val: str) -> bool:
|
|
59
|
+
"""Check if the string is valid request ID.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
val (str, required): String to check.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
bool: True if the string is valid request ID, False otherwise.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
_is_valid = bool(re.match(pattern=REQUEST_ID_REGEX, string=val))
|
|
69
|
+
return _is_valid
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@validate_call
|
|
73
|
+
def is_blacklisted(val: str, blacklist: list[str]) -> bool:
|
|
74
|
+
"""Check if the string is blacklisted.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
val (str , required): String to check.
|
|
78
|
+
blacklist (List[str], required): List of blacklisted strings.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
bool: True if the string is blacklisted, False otherwise.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
for _blacklisted in blacklist:
|
|
85
|
+
if _blacklisted in val:
|
|
86
|
+
return True
|
|
87
|
+
|
|
88
|
+
return False
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@validate_call
|
|
92
|
+
def is_valid(val: str, pattern: Pattern | str) -> bool:
|
|
93
|
+
"""Check if the string is valid with given pattern.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
val (str , required): String to check.
|
|
97
|
+
pattern (Union[Pattern, str], required): Pattern regex to check.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
bool: True if the string is valid with given pattern, False otherwise.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
_is_valid = bool(re.match(pattern=pattern, string=val))
|
|
104
|
+
return _is_valid
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@validate_call
|
|
108
|
+
def has_special_chars(val: str, mode: str = "LOW") -> bool:
|
|
109
|
+
"""Check if the string has special characters.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
val (str, required): String to check.
|
|
113
|
+
mode (str, optional): Check mode. Defaults to "LOW".
|
|
114
|
+
|
|
115
|
+
Raises:
|
|
116
|
+
ValueError: If `mode` is unsupported.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
bool: True if the string has special characters, False otherwise.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
_has_special_chars = False
|
|
123
|
+
|
|
124
|
+
_pattern = r""
|
|
125
|
+
mode = mode.upper().strip()
|
|
126
|
+
if (mode == "BASE") or (mode == "HTML"):
|
|
127
|
+
_pattern = SPECIAL_CHARS_BASE_REGEX
|
|
128
|
+
elif mode == "LOW":
|
|
129
|
+
_pattern = SPECIAL_CHARS_LOW_REGEX
|
|
130
|
+
elif mode == "MEDIUM":
|
|
131
|
+
_pattern = SPECIAL_CHARS_MEDIUM_REGEX
|
|
132
|
+
elif (mode == "HIGH") or (mode == "SCRIPT") or (mode == "SQL"):
|
|
133
|
+
_pattern = SPECIAL_CHARS_HIGH_REGEX
|
|
134
|
+
elif mode == "STRICT":
|
|
135
|
+
_pattern = SPECIAL_CHARS_STRICT_REGEX
|
|
136
|
+
else:
|
|
137
|
+
raise ValueError(f"Unsupported mode: {mode}")
|
|
138
|
+
|
|
139
|
+
_has_special_chars = bool(re.search(pattern=_pattern, string=val))
|
|
140
|
+
return _has_special_chars
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
__all__ = [
|
|
144
|
+
"is_truthy",
|
|
145
|
+
"is_falsy",
|
|
146
|
+
"is_request_id",
|
|
147
|
+
"is_blacklisted",
|
|
148
|
+
"is_valid",
|
|
149
|
+
"has_special_chars",
|
|
150
|
+
]
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: potato_util
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: 'potato_util' is collection of simple useful utils package for python.
|
|
5
|
+
Author-email: Batkhuu Byambajav <batkhuu10@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/bybatkhuu/module.python-utils
|
|
7
|
+
Project-URL: Documentation, https://pyutils-docs.bybatkhuu.dev
|
|
8
|
+
Project-URL: Repository, https://github.com/bybatkhuu/module.python-utils.git
|
|
9
|
+
Project-URL: Issues, https://github.com/bybatkhuu/module.python-utils/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/bybatkhuu/module.python-utils/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: potato_util,utils,utilities,tools,helpers
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Requires-Python: <4.0,>=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE.txt
|
|
24
|
+
Requires-Dist: python-dotenv<2.0.0,>=1.0.1
|
|
25
|
+
Requires-Dist: pydantic[email,timezone]<3.0.0,>=2.0.3
|
|
26
|
+
Requires-Dist: pydantic-settings<3.0.0,>=2.2.1
|
|
27
|
+
Provides-Extra: async
|
|
28
|
+
Requires-Dist: aiofiles<25.0.0,>=24.1.0; extra == "async"
|
|
29
|
+
Requires-Dist: aioshutil<2.0.0,>=1.5; extra == "async"
|
|
30
|
+
Requires-Dist: aiohttp<4.0.0,>=3.11.18; extra == "async"
|
|
31
|
+
Provides-Extra: fastapi
|
|
32
|
+
Requires-Dist: fastapi<1.0.0,>=0.109.2; extra == "fastapi"
|
|
33
|
+
Provides-Extra: all
|
|
34
|
+
Requires-Dist: aiofiles<25.0.0,>=24.1.0; extra == "all"
|
|
35
|
+
Requires-Dist: aioshutil<2.0.0,>=1.5; extra == "all"
|
|
36
|
+
Requires-Dist: aiohttp<4.0.0,>=3.11.18; extra == "all"
|
|
37
|
+
Requires-Dist: fastapi<1.0.0,>=0.109.2; extra == "all"
|
|
38
|
+
Provides-Extra: test
|
|
39
|
+
Requires-Dist: aiofiles<25.0.0,>=24.1.0; extra == "test"
|
|
40
|
+
Requires-Dist: aioshutil<2.0.0,>=1.5; extra == "test"
|
|
41
|
+
Requires-Dist: aiohttp<4.0.0,>=3.11.18; extra == "test"
|
|
42
|
+
Requires-Dist: fastapi<1.0.0,>=0.109.2; extra == "test"
|
|
43
|
+
Requires-Dist: pytest<9.0.0,>=8.0.2; extra == "test"
|
|
44
|
+
Requires-Dist: pytest-cov<8.0.0,>=5.0.0; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-xdist<4.0.0,>=3.6.1; extra == "test"
|
|
46
|
+
Requires-Dist: pytest-benchmark<6.0.0,>=5.0.1; extra == "test"
|
|
47
|
+
Provides-Extra: build
|
|
48
|
+
Requires-Dist: setuptools<81.0.0,>=70.3.0; extra == "build"
|
|
49
|
+
Requires-Dist: wheel<1.0.0,>=0.43.0; extra == "build"
|
|
50
|
+
Requires-Dist: build<2.0.0,>=1.1.1; extra == "build"
|
|
51
|
+
Requires-Dist: twine<7.0.0,>=6.0.1; extra == "build"
|
|
52
|
+
Provides-Extra: docs
|
|
53
|
+
Requires-Dist: pylint<4.0.0,>=3.0.4; extra == "docs"
|
|
54
|
+
Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "docs"
|
|
55
|
+
Requires-Dist: mkdocs-awesome-nav<4.0.0,>=3.0.0; extra == "docs"
|
|
56
|
+
Requires-Dist: mkdocstrings[python]<1.0.0,>=0.24.3; extra == "docs"
|
|
57
|
+
Requires-Dist: mike<3.0.0,>=2.1.3; extra == "docs"
|
|
58
|
+
Provides-Extra: dev
|
|
59
|
+
Requires-Dist: aiofiles<25.0.0,>=24.1.0; extra == "dev"
|
|
60
|
+
Requires-Dist: aioshutil<2.0.0,>=1.5; extra == "dev"
|
|
61
|
+
Requires-Dist: aiohttp<4.0.0,>=3.11.18; extra == "dev"
|
|
62
|
+
Requires-Dist: fastapi<1.0.0,>=0.109.2; extra == "dev"
|
|
63
|
+
Requires-Dist: pytest<9.0.0,>=8.0.2; extra == "dev"
|
|
64
|
+
Requires-Dist: pytest-cov<8.0.0,>=5.0.0; extra == "dev"
|
|
65
|
+
Requires-Dist: pytest-xdist<4.0.0,>=3.6.1; extra == "dev"
|
|
66
|
+
Requires-Dist: pytest-benchmark<6.0.0,>=5.0.1; extra == "dev"
|
|
67
|
+
Requires-Dist: setuptools<81.0.0,>=70.3.0; extra == "dev"
|
|
68
|
+
Requires-Dist: wheel<1.0.0,>=0.43.0; extra == "dev"
|
|
69
|
+
Requires-Dist: build<2.0.0,>=1.1.1; extra == "dev"
|
|
70
|
+
Requires-Dist: twine<7.0.0,>=6.0.1; extra == "dev"
|
|
71
|
+
Requires-Dist: pylint<4.0.0,>=3.0.4; extra == "dev"
|
|
72
|
+
Requires-Dist: mkdocs-material<10.0.0,>=9.5.50; extra == "dev"
|
|
73
|
+
Requires-Dist: mkdocs-awesome-nav<4.0.0,>=3.0.0; extra == "dev"
|
|
74
|
+
Requires-Dist: mkdocstrings[python]<1.0.0,>=0.24.3; extra == "dev"
|
|
75
|
+
Requires-Dist: mike<3.0.0,>=2.1.3; extra == "dev"
|
|
76
|
+
Requires-Dist: pyright<2.0.0,>=1.1.392; extra == "dev"
|
|
77
|
+
Requires-Dist: pre-commit<5.0.0,>=4.0.1; extra == "dev"
|
|
78
|
+
Dynamic: license-file
|
|
79
|
+
|
|
80
|
+
# Potato Utils (Python Utils)
|
|
81
|
+
|
|
82
|
+
[](https://choosealicense.com/licenses/mit)
|
|
83
|
+
[](https://github.com/bybatkhuu/module.python-utils/actions/workflows/2.build-publish.yml)
|
|
84
|
+
[](https://github.com/bybatkhuu/module.python-utils/releases)
|
|
85
|
+
|
|
86
|
+
'potato_util' is collection of simple useful utils package for python.
|
|
87
|
+
|
|
88
|
+
## โจ Features
|
|
89
|
+
|
|
90
|
+
- Python utilities
|
|
91
|
+
- Datetime utilities
|
|
92
|
+
- File I/O utilities
|
|
93
|
+
- HTTP utilities
|
|
94
|
+
- Security utilities
|
|
95
|
+
- Sanitation utilities
|
|
96
|
+
- Validation utilities
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## ๐ Installation
|
|
101
|
+
|
|
102
|
+
### 1. ๐ง Prerequisites
|
|
103
|
+
|
|
104
|
+
- Install **Python (>= v3.10)** and **pip (>= 23)**:
|
|
105
|
+
- **[RECOMMENDED] [Miniconda (v3)](https://www.anaconda.com/docs/getting-started/miniconda/install)**
|
|
106
|
+
- *[arm64/aarch64] [Miniforge (v3)](https://github.com/conda-forge/miniforge)*
|
|
107
|
+
- *[Python virutal environment] [venv](https://docs.python.org/3/library/venv.html)*
|
|
108
|
+
|
|
109
|
+
[OPTIONAL] For **DEVELOPMENT** environment:
|
|
110
|
+
|
|
111
|
+
- Install [**git**](https://git-scm.com/downloads)
|
|
112
|
+
- Setup an [**SSH key**](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh) ([video tutorial](https://www.youtube.com/watch?v=snCP3c7wXw0))
|
|
113
|
+
|
|
114
|
+
### 2. ๐ฅ Download or clone the repository
|
|
115
|
+
|
|
116
|
+
[TIP] Skip this step, if you're going to install the package directly from **PyPi** or **GitHub** repository.
|
|
117
|
+
|
|
118
|
+
**2.1.** Prepare projects directory (if not exists):
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
# Create projects directory:
|
|
122
|
+
mkdir -pv ~/workspaces/projects
|
|
123
|
+
|
|
124
|
+
# Enter into projects directory:
|
|
125
|
+
cd ~/workspaces/projects
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**2.2.** Follow one of the below options **[A]**, **[B]** or **[C]**:
|
|
129
|
+
|
|
130
|
+
**OPTION A.** Clone the repository:
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
git clone https://github.com/bybatkhuu/module.python-utils.git && \
|
|
134
|
+
cd module.python-utils
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**OPTION B.** Clone the repository (for **DEVELOPMENT**: git + ssh key):
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
git clone git@github.com:bybatkhuu/module.python-utils.git && \
|
|
141
|
+
cd module.python-utils
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**OPTION C.** Download source code:
|
|
145
|
+
|
|
146
|
+
1. Download archived **zip** file from [**releases**](https://github.com/bybatkhuu/module.python-utils/releases).
|
|
147
|
+
2. Extract it into the projects directory.
|
|
148
|
+
|
|
149
|
+
### 3. ๐ฆ Install the package
|
|
150
|
+
|
|
151
|
+
[NOTE] Choose one of the following methods to install the package **[A ~ F]**:
|
|
152
|
+
|
|
153
|
+
**OPTION A.** [**RECOMMENDED**] Install from **PyPi**:
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
pip install -U potato_util
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**OPTION B.** Install latest version directly from **GitHub** repository:
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
pip install git+https://github.com/bybatkhuu/module.python-utils.git
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**OPTION C.** Install from the downloaded **source code**:
|
|
166
|
+
|
|
167
|
+
```sh
|
|
168
|
+
# Install directly from the source code:
|
|
169
|
+
pip install .
|
|
170
|
+
|
|
171
|
+
# Or install with editable mode:
|
|
172
|
+
pip install -e .
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**OPTION D.** Install for **DEVELOPMENT** environment:
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
pip install -e .[dev]
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**OPTION E.** Install from **pre-built release** files:
|
|
182
|
+
|
|
183
|
+
1. Download **`.whl`** or **`.tar.gz`** file from [**releases**](https://github.com/bybatkhuu/module.python-utils/releases)
|
|
184
|
+
2. Install with pip:
|
|
185
|
+
|
|
186
|
+
```sh
|
|
187
|
+
# Install from .whl file:
|
|
188
|
+
pip install ./potato_util-[VERSION]-py3-none-any.whl
|
|
189
|
+
|
|
190
|
+
# Or install from .tar.gz file:
|
|
191
|
+
pip install ./potato_util-[VERSION].tar.gz
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**OPTION F.** Copy the **module** into the project directory (for **testing**):
|
|
195
|
+
|
|
196
|
+
```sh
|
|
197
|
+
# Install python dependencies:
|
|
198
|
+
pip install -r ./requirements.txt
|
|
199
|
+
|
|
200
|
+
# Copy the module source code into the project:
|
|
201
|
+
cp -r ./src/potato_util [PROJECT_DIR]
|
|
202
|
+
# For example:
|
|
203
|
+
cp -r ./src/potato_util /some/path/project/
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## ๐ธ Usage/Examples
|
|
207
|
+
|
|
208
|
+
### Simple
|
|
209
|
+
|
|
210
|
+
[**`examples/simple/main.py`**](./examples/simple/main.py):
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
๐
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### ๐ Environment Variables
|
|
220
|
+
|
|
221
|
+
[**`.env.example`**](./.env.example):
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
# ENV=LOCAL
|
|
225
|
+
# DEBUG=false
|
|
226
|
+
# TZ=UTC
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## ๐งช Running Tests
|
|
232
|
+
|
|
233
|
+
To run tests, run the following command:
|
|
234
|
+
|
|
235
|
+
```sh
|
|
236
|
+
# Install python test dependencies:
|
|
237
|
+
pip install .[test]
|
|
238
|
+
|
|
239
|
+
# Run tests:
|
|
240
|
+
python -m pytest -sv -o log_cli=true
|
|
241
|
+
# Or use the test script:
|
|
242
|
+
./scripts/test.sh -l -v -c
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## ๐๏ธ Build Package
|
|
246
|
+
|
|
247
|
+
To build the python package, run the following command:
|
|
248
|
+
|
|
249
|
+
```sh
|
|
250
|
+
# Install python build dependencies:
|
|
251
|
+
pip install -r ./requirements/requirements.build.txt
|
|
252
|
+
|
|
253
|
+
# Build python package:
|
|
254
|
+
python -m build
|
|
255
|
+
# Or use the build script:
|
|
256
|
+
./scripts/build.sh
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## ๐ Generate Docs
|
|
260
|
+
|
|
261
|
+
To build the documentation, run the following command:
|
|
262
|
+
|
|
263
|
+
```sh
|
|
264
|
+
# Install python documentation dependencies:
|
|
265
|
+
pip install -r ./requirements/requirements.docs.txt
|
|
266
|
+
|
|
267
|
+
# Serve documentation locally (for development):
|
|
268
|
+
mkdocs serve -a 0.0.0.0:8000
|
|
269
|
+
# Or use the docs script:
|
|
270
|
+
./scripts/docs.sh
|
|
271
|
+
|
|
272
|
+
# Or build documentation:
|
|
273
|
+
mkdocs build
|
|
274
|
+
# Or use the docs script:
|
|
275
|
+
./scripts/docs.sh -b
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## ๐ Documentation
|
|
279
|
+
|
|
280
|
+
- [Docs](./docs)
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## ๐ References
|
|
285
|
+
|
|
286
|
+
- <https://packaging.python.org/en/latest/tutorials/packaging-projects>
|
|
287
|
+
- <https://python-packaging.readthedocs.io/en/latest>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
potato_util/__init__.py,sha256=HjN2VbjR-wQBNVKpcRa4fgLaqEcNOQVhRoKQCilFjAM,72
|
|
2
|
+
potato_util/__version__.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
|
|
3
|
+
potato_util/_base.py,sha256=x_wIKThJPRi25gI_Ab4hvr6Qg-7RaMfN9dbjpeEPI0g,2923
|
|
4
|
+
potato_util/dt.py,sha256=EMT4r4b-KFWwyStDJ8ajUXci3vnP1cMwJafniwUxxJA,6872
|
|
5
|
+
potato_util/sanitizer.py,sha256=-olqyjG9PorIciV90M5Q4r0g_-0tXC7DJcO7xuHEcPs,1860
|
|
6
|
+
potato_util/secure.py,sha256=gngUBve3fhTjPop92t4gfOKhfWwG3MU7FlvzSwJJgtk,2247
|
|
7
|
+
potato_util/validator.py,sha256=7wOTBuV4MbYNS1CMOOcpIdG2Qjp7yzPWR21LTLZdJpA,3757
|
|
8
|
+
potato_util/constants/__init__.py,sha256=lhxZ2k-QotMR_w9w-Gv-9pCEFrQSKxe1YEIvV83pf8E,80
|
|
9
|
+
potato_util/constants/_base.py,sha256=J1i611erzcrPRZ6USkVgnNZ_IvvN9YLbcltvyIngpcg,61
|
|
10
|
+
potato_util/constants/_enum.py,sha256=tThmf7lFsGfFUNNQE0hOUZ0JKc821ZGZnSyJIj2jVTQ,515
|
|
11
|
+
potato_util/constants/_regex.py,sha256=T7SSsqD0y8jXJJPURwAK2uA59AjLt1uqGfqqUd1a22o,710
|
|
12
|
+
potato_util/http/__init__.py,sha256=qWOzScMVJEHjzClEqOYmGtfkZyU8f8Hz8nT054Dbblo,229
|
|
13
|
+
potato_util/http/_async.py,sha256=dfs-ynchPKdnMNQXqyoqhcz-jhtQ7g_4JnNfVr3bXk0,1178
|
|
14
|
+
potato_util/http/_base.py,sha256=01r87dsY9mNnCTsAsBNfN1TEL_Y_bLSgcX5SxJaZT2I,1365
|
|
15
|
+
potato_util/http/_sync.py,sha256=i8oyRmh-WraOzotaUbssIjOPvBh1pvLPupdoCvyHTK0,1169
|
|
16
|
+
potato_util/http/fastapi.py,sha256=3zE6KvmGDaDokWxxstoEj4OBCBgp6n-vqvS0jQZqPHk,671
|
|
17
|
+
potato_util/io/__init__.py,sha256=FoGcN7t0uArQV4hbMR1X5aeC8Yq-h_ds4xooNpkmgG0,209
|
|
18
|
+
potato_util/io/_async.py,sha256=xDBnMcU7PF8dfVMrJRTYJirU9yqprza30YMgyWbCKjY,9486
|
|
19
|
+
potato_util/io/_sync.py,sha256=cPFlfxKsLVH4NtNOccUt2z8a9K2MkW2GxtJbCXyWVqY,9106
|
|
20
|
+
potato_util-0.0.1.dist-info/licenses/LICENSE.txt,sha256=CUTK-r0BWIg1r0bBiemAcMhakgV0N7HuRhw6rQ-A9A4,1074
|
|
21
|
+
potato_util-0.0.1.dist-info/METADATA,sha256=Z8Zm6HTW6jGtMT7brhpVza-2O21vo8pXGzUG2A9eUNo,8999
|
|
22
|
+
potato_util-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
23
|
+
potato_util-0.0.1.dist-info/top_level.txt,sha256=pLMnSfT6rhlYBpo2Gnd8kKMDxcuvxdVizqsv1dd1frw,12
|
|
24
|
+
potato_util-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Batkhuu Byambajav
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
potato_util
|