Python toolkit for corpus generation, utility functions, and Nacos config center
Project description
sololib
一个 Python 工具包(v0.3.7),提供 语料生成、通用工具集 和 Nacos 配置中心 三大功能模块。
安装
pip install sololib
# 或
uv add sololib
# 可选依赖(图像处理)
pip install sololib[image]
# 可选依赖(Windows 窗口管理)
pip install sololib[win32]
快速开始
1. 语料生成 (sololib.corpus)
基于 30 个变量池(每池 30 值)和 500+ 中英文问题模板,随机生成对话数据。
from sololib import get_random_conversation
# 生成单轮对话
q, topic = get_random_conversation()
print(f"[{topic}] {q}")
# 批量生成
conversations = get_random_conversation(n=10)
# 批量生成随机问题
from sololib import generate_questions
questions = generate_questions(n=5)
# 生成单个问题
from sololib import generate_single_question
single = generate_single_question()
# 查看语料统计
from sololib import get_corpus_stats
stats = get_corpus_stats()
# 估算模板组合数
from sololib import estimate_combinations
total = estimate_combinations()
概率模型:
- 中文概率:10%,追问概率:50%,三轮追问条件概率:40%
- 自动中英文分离(通过 Unicode 范围检测)
2. 通用工具集 (sololib.utils)
# ---- 异步命令执行 ----
from sololib.utils import run_command
import asyncio
result = await run_command("ls -la", timeout=30)
# {"stdout": "...", "stderr": "...", "returncode": 0}
# ---- 重试装饰器(同步/异步自适应)----
from sololib.utils import retry
@retry(max_retries=3, delay=3.0)
def flaky_function():
...
@retry(max_retries=5, delay=1.0)
async def async_flaky_function():
...
# ---- 递归字典合并 ----
from sololib.utils import merge_dicts
merged = merge_dicts({"a": {"x": 1}}, {"a": {"y": 2}})
# {"a": {"x": 1, "y": 2}}
# ---- 异步 HTTP POST ----
from sololib.utils import post_data
result = await post_data("https://api.example.com/data", {"key": "value"})
# ---- Pydantic 统一响应模型 ----
from sololib.utils import success, error, result, result_page, ResponseModel
resp = success() # ResponseModel(code=200, message="success")
resp = result({"id": 1}) # ResponseModel(code=200, message="success", data={"id": 1})
resp = error(400, "Bad request")
resp = result_page([{"id": 1}], total=100)
# ---- PyPI 版本检查 ----
from sololib.utils import check_package_update, update_package, get_current_version
needs_update = check_package_update("sololib", "0.3.5")
update_package("sololib", "0.3.5")
# ---- YAML 配置加载 ----
from sololib.utils import load_config
from dataclasses import dataclass
@dataclass
class AppConfig:
host: str
port: int
config = load_config("app.yaml", AppConfig)
# ---- 日志(可选依赖 loguru)----
from sololib.utils import setup_logger, get_logger, logger
setup_logger(log_dir="logs", level="INFO")
my_logger = get_logger(__name__)
logger.info("Hello, world!")
3. Nacos 配置中心 (sololib.configs)
基于 nacos-sdk-python v3 全异步 gRPC API,对外暴露同步接口,支持配置热更新。
from sololib.configs import NacosConfig, NacosStore
# 初始化配置(连接 Nacos 并自动拉取所有配置)
nacos_config = NacosConfig(
server_addresses="127.0.0.1:9848",
namespace="public",
username="nacos",
password="nacos",
configs=[
NacosConfig.ConfigItem(data_id="app.yaml", group="DEFAULT_GROUP"),
NacosConfig.ConfigItem(data_id="db.yaml", group="DEFAULT_GROUP"),
],
)
store = NacosStore(nacos_config, is_watcher=True)
# 获取合并后的完整配置
config = store.get_config()
# 手动刷新
store.refresh_config()
# 关闭连接
store.close()
版本要求
- Python >= 3.11
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sololib-0.3.7.5.tar.gz.
File metadata
- Download URL: sololib-0.3.7.5.tar.gz
- Upload date:
- Size: 170.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87971d0e95dcdd9c94802dde08fec1e70af114364d54bae60df4a2ce5e1882fb
|
|
| MD5 |
938f71697b7664463a52bb05ecaacf47
|
|
| BLAKE2b-256 |
d5875961261c25ad1155d959314b7ed4cd2a43f7745ef740cc65069983edaab3
|
Provenance
The following attestation bundles were made for sololib-0.3.7.5.tar.gz:
Publisher:
sololibpypi.yml on iding2959/sololib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sololib-0.3.7.5.tar.gz -
Subject digest:
87971d0e95dcdd9c94802dde08fec1e70af114364d54bae60df4a2ce5e1882fb - Sigstore transparency entry: 1448615556
- Sigstore integration time:
-
Permalink:
iding2959/sololib@2e130b412e99764b61a620e8867fd4ae8a0f277f -
Branch / Tag:
refs/tags/v0.3.7.5 - Owner: https://github.com/iding2959
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sololibpypi.yml@2e130b412e99764b61a620e8867fd4ae8a0f277f -
Trigger Event:
push
-
Statement type:
File details
Details for the file sololib-0.3.7.5-py3-none-any.whl.
File metadata
- Download URL: sololib-0.3.7.5-py3-none-any.whl
- Upload date:
- Size: 41.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e4f03ac31182840ead6425d63ab8ef147a19e1388432131ba457f2f9c3ca873
|
|
| MD5 |
40698d56e285cfa77f741da6cfcc006a
|
|
| BLAKE2b-256 |
f3bc79cd3b0f004616c7752a08e7a02e546321d1f4f91d716078fc7493de9891
|
Provenance
The following attestation bundles were made for sololib-0.3.7.5-py3-none-any.whl:
Publisher:
sololibpypi.yml on iding2959/sololib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sololib-0.3.7.5-py3-none-any.whl -
Subject digest:
2e4f03ac31182840ead6425d63ab8ef147a19e1388432131ba457f2f9c3ca873 - Sigstore transparency entry: 1448615645
- Sigstore integration time:
-
Permalink:
iding2959/sololib@2e130b412e99764b61a620e8867fd4ae8a0f277f -
Branch / Tag:
refs/tags/v0.3.7.5 - Owner: https://github.com/iding2959
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sololibpypi.yml@2e130b412e99764b61a620e8867fd4ae8a0f277f -
Trigger Event:
push
-
Statement type: