Metadata-Version: 2.4
Name: mini-common-utils
Version: 0.1.0
Summary: Common Python utilities: cache, captcha, date, eval, http, string, thread
Project-URL: Homepage, https://gitee.com/py-common-utils
Author: mini-common-utils contributors
License: MIT License
        
        Copyright (c) 2024 common-utils contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: cache,captcha,common,http,utils
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Requires-Dist: loguru>=0.7.0
Requires-Dist: pillow>=9.0.0
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == 'dev'
Description-Content-Type: text/markdown

# common-utils

A collection of common Python utility modules: cache, captcha, date, safe expression evaluation, HTTP requests, string helpers, and threading helpers.

## Install

From source (editable, recommended for development):

```bash
pip install -e .
```

From a built distribution:

```bash
pip install dist/common_utils-0.1.0-py3-none-any.whl
```

Requires Python 3.8+.

## Modules

### `common_utils.cache` — Local in-memory cache
```python
from common_utils.cache.Cache import LocalCache

LocalCache.set_data("user:1", {"name": "alice"}, expire=60)
user = LocalCache.get_data("user:1")
```

### `common_utils.captcha` — Math captcha image
```python
from common_utils.captcha.captcha_util import generate_captcha_image

img_bytes, answer = generate_captcha_image()
# answer 是形如 "12" 的字符串，前端展示 img_bytes，校验用户输入
```

### `common_utils.date` — Date/time helpers (UTC+8)
```python
from common_utils.date.date_utils import current_date_time_str, current_date_str

print(current_date_time_str())  # '2024-05-20 18:30:00'
print(current_date_str())       # '2024-05-20'
```

### `common_utils.eval` — Safe arithmetic evaluator
```python
from common_utils.eval.eval_utils import safe_eval_expr

safe_eval_expr("60*60*7")  # 25200
```

### `common_utils.http` — HTTP helpers
```python
from common_utils.http.http_request_utils import http_post_json
from common_utils.http.http_param_utils import build_timeout_param

connect_t, read_t = build_timeout_param(data_count=500)
resp = http_post_json("https://api.example.com/echo", {"a": 1}, timeout_param=(connect_t, read_t))
```

### `common_utils.string` — String helpers
```python
from common_utils.string.string_utils import is_empty_common, contains_chinese

is_empty_common("  ")        # True
is_empty_common([])          # True
is_empty_common("hello")     # False
contains_chinese("你好")      # True
```

### `common_utils.thread` — Threading helpers
```python
from common_utils.thread.thread_utils import run_function_in_thread

t = run_function_in_thread(my_func, (arg1, arg2))
t.join()
```

## Build a distribution

```bash
pip install build
python -m build
# 产物在 dist/
```

## License

MIT
